开发者

Create tables from SQL dump generated by phpmyadmin using kohana

I have a PHPMyAdmin SQL dump in a file. I want to use PHP to execute this SQL. How could I 开发者_如何学Godo 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?


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.


$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.


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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜