473,395 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem - Error: No database selected!

Hello,

I have a simple Perl program that connects to MySQL and creates a table of
first names and last names. The code is as follows :
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use DBI;
  3. use Mysql;
  4. use DBD::mysql;
  5.  
  6. $dbname = '';
  7. $dbhost   = 'localhost';
  8. $dbuser   = 'root';
  9. $dbpass  = '';
  10.  
  11. $dbh = DBI->connect("DBI:mysql:dbname=$dbname:$dbhost", $dbuser,           
  12.                                   $dbpass || die "Error: $DBI::errstr!\n";
  13. $create = $dbh->prepare("CREATE TABLE people ( first varchar (32) not null,
  14.                                                                             last varchar (32) not null )
  15.                                      ");
  16. $create->execute() || die "Error: $DBI::errstr!\n";
  17.  
When I ran this program, I got the following error messages :
(line 16 is the execute statement)

DBD::mysql::st execute failed: No database selected at mkdb.pl line 16
Error: No database selected!

Are these errors caused by $dbname being empty? Do I need to assign a name to $dbname? Does the name of the database already exist somewhere or do I need to come up with this name?

Your help is much appreciated.

Akino.
Nov 14 '07 #1
1 3925
eWish
971 Expert 512MB
I would say the problem is because a database name was not specified. Yes, you will need to have a vlaue for $dbname. And a value for $dbpass as well.

When making table names it is good pratice to not use reserved words. I know that you have not at this point, just wanted to let you know.

--Kevin
Nov 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: middletree | last post by:
Posted this to Access group, meant to do it here: I have what I call a composite table. Can't recall what they called it in database class, but it's where you take the PK of two different...
3
by: Phil | last post by:
Hi, I have a client/server app. that uses a windows service for the server and asp.net web pages for the client side. My server class has 3 methods that Fill, Add a new record and Update a record....
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
3
by: Chris H | last post by:
Ok in the following code I am trying to have my keywards meta tag auto insert the top 10 titles from most recently added database entries, right now the while loop is only setting the $keyword...
3
by: deena22 | last post by:
hello, i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
2
by: olud | last post by:
Hi All, I am trying to insert selected contents of a listbox into a database by looping through the collection. The loop is working and the contents are going into the database. Starnge thing is...
6
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.