Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: DBD::mysql::db do failed: You have an error in your SQL syntax;

by rnewsham (Curate)
on Jan 05, 2015 at 12:45 UTC ( [id://1112184]=note: print w/replies, xml ) Need Help??


in reply to Re: DBD::mysql::db do failed: You have an error in your SQL syntax;
in thread DBD::mysql::db do failed: You have an error in your SQL syntax;

You can have a dash in a database name if it is done inside backticks

mysql> create database `test-dash`; Query OK, 1 row affected (0.05 sec)
  • Comment on Re^2: DBD::mysql::db do failed: You have an error in your SQL syntax;
  • Download Code

Replies are listed 'Best First'.
Re^3: DBD::mysql::db do failed: You have an error in your SQL syntax;
by shajiindia (Acolyte) on Jan 05, 2015 at 13:07 UTC
    Thanks rnewsham. It worked like a champ Modified code
    sub create_database { print "Please enter the hostname:"; chomp($hostname = <STDIN>); print "Please enter the name of the new MySQL database:"; chomp($database = <STDIN>); $dsn = "dbi:$driver::$hostname:$port"; print "Please type the MySQL root username:"; chomp($username = <STDIN>); print "Please type the MySQL root password:"; chomp($password = <STDIN>); $dbh = DBI->connect($dsn, $username, $password); $result = $dbh->do("create database `$database`"); $dbh->do("use `$database`"); if($result) { say "Database '$database' created successfully"; } else { say "Database '$database' creation failed"; exit; } }
Re^3: DBD::mysql::db do failed: You have an error in your SQL syntax;
by KurtSchwind (Chaplain) on Jan 05, 2015 at 12:54 UTC

    Forgot about back-tick quoting in MYSQL. Yep. That'll work.

    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1112184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found