2

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?

thomas
  • 21
  • 2

3 Answers3

2

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.

The Pixel Developer
  • 13,064
  • 10
  • 41
  • 59
0
$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.

alex
  • 460,746
  • 196
  • 858
  • 974
0

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");
sholsinger
  • 2,960
  • 1
  • 21
  • 40