2

I'm trying to import .sql file into mysql database using php but I can't

Am using like this code:

<?php

$sql = mysqli_connect('localhost', 'root', '123123', '');
mysqli_query($sql, "USE vmail");
mysqli_query($sql, "source insert.sql");
mysqli_close($sql);

echo ("Done")


?>

How can I import it??

thnx.

deounix
  • 141
  • 2
  • 4
  • 18
  • 2
    Duplicate of [how to import .sql file in mysql database using php](http://stackoverflow.com/questions/19751354/how-to-import-sql-file-in-mysql-database-using-php) – adarsh hota Feb 24 '15 at 11:23
  • 2
    looks like duplicate of this http://stackoverflow.com/questions/19751354/how-to-import-sql-file-in-mysql-database-using-php – user1627167 Feb 24 '15 at 11:24

1 Answers1

13

Try this code. You have to read the sql file first and than execute:

eg:

$sqlSource = file_get_contents('insert.sql');

mysqli_multi_query($sql,$sqlSource);
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
teo
  • 801
  • 6
  • 14