http://qs321.pair.com?node_id=1112184


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.