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?
Asked
Active
Viewed 860 times
3 Answers
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,282
- 10
- 43
- 60
-
what if i am on shared hosting and cannot use shell – Imran Naqvi Jun 11 '11 at 10:12
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
- 479,566
- 201
- 878
- 984
-
-
-
-
@thomas There no reason why it shouldn't. I suggest you take [The Pixel Developer's advice](http://stackoverflow.com/questions/4433723/create-tables-from-sql-dump-generated-by-phpmyadmin-using-kohana/4441039#4441039) on this one. – alex Dec 15 '10 at 06:30
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
- 3,028
- 2
- 23
- 40