Linus Norton Linus Norton - 18 days ago 6
MySQL Question

Using MySQL "SOURCE /path/to/file.sql" with PDO

This works when I run it from the mysql cli client but not when I run it through PDO, does anyone know why?

Answer

source is a command that allow you to execute list of SQL in mysql CLI,
but PDO is a database driver library (api) that compiled into PHP,
both are in different domain

Details of source :-

https://dev.mysql.com/doc/refman/5.7/en/mysql-batch-commands.html
http://dev.mysql.com/doc/refman/5.0/en/batch-mode.html

You can either :-

exec("/PATH/mysql < $file");

Or break each line of SQL (inside the file),
execute one-by-one each in PDO

Comments