471,066 Members | 1,242 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 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 3699
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

Post your reply

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

Similar topics

7 posts views Thread by middletree | last post: by
3 posts views Thread by Phil | last post: by
5 posts views Thread by Vigneshwar Pilli via DotNetMonster.com | last post: by
10 posts views Thread by ads | last post: by
3 posts views Thread by Chris H | last post: by
reply views Thread by leo001 | last post: by

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.