Create tables from SQL dump generated by phpmyadmin using kohana

a 夏天 提交于 2019-12-12 20:36:10

问题


I have a PHPMyAdmin SQL dump in a file. I want to use PHP to execute this SQL. How could I do that? I've tried a simple query (with Kohana but without it is enough too!) but I got a syntax error. How could I do that?


回答1:


Well this has nothing to do with Kohana. I would recommend you not do this through PHP as you then have memory and time constraints. If you can, use the terminal.

mysql -u [username] -p [password] [database name] < [filename.sql]

Replacing [value] with their respective values.




回答2:


$sql = file_get_contents('sql_dump.sql');

mysql_query($sql);

I thought about using Kohana's Db::query(Database::INSERT, $sql)->execute(), but I'm not sure if it will work. Try it.




回答3:


I agree with The Pixel Developer. However, you could use PHP to initiate the command using shell_exec Eg:

$result = shell_exec("mysql -h {$hostname} -u {$username} -p {$password} {$database} < $input_file");


来源:https://stackoverflow.com/questions/4433723/create-tables-from-sql-dump-generated-by-phpmyadmin-using-kohana

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!