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.

2

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Will this work when file contains comments or empty lines ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.