My fellow Perl Monks,
I've come across an issue with using DBI/DBD::mysql when connecting to a remote MySQL database.
I can achieve the connection and query it just fine, however it seems that when I connect to a remote host I am required to specify the tables in my statements in the 'database.table' format instead of being able to shorthand it to just 'table' like all the documentation would lead me to believe was possible (per examples in DBD::mysql).
As an example of my connection code...
my $dsn = "dbi:$driver:database=$database;host=$host;port=$port"; my $dbh = DBI->connect( $dsn, $cfg->{username}, $cfg->{password}, { AutoCommit => 1, RaiseError => 0, PrintError => 0, PrintWarn => 0, }, );
Again, I am able to connect and query the database just fine, but if I do not prepend the database name to the table in my SQL statements, it will return an error.
An example SQL statement...
SELECT * FROM group
The database will return the following...
You have an error in your SQL syntax; check the manual that correspo +nds to your MySQL server version for the right syntax to use near 'gr +oup' at line 2
All I have to change to make it work is prepending "$database." to my table 'group'.
If I check the dbh attribute Name, it will return the entire dsn minus the 'dbi:mysql:' at the front of it.
I have even tried doing a $dbh->do("USE $database;") on the connection, but it still requires me to prepend the database name to my table names in my SQL statements.
Is this expected behavior?
In reply to Solved: DBI and MySQL not setting database properly by KolassaRaptor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |