0

i have mysql file. it has .sql extension. how to run that "mysql" file using php script? how is the script should be? the mysql file is already on the server, and i want to run this query using php file which is placed on the same place with mysql file...

1

2 Answers 2

2

You could do this

$query=file_get_contents($file);

$mysqli->multi_query($query);

mysqli::multi_query can do the job.

Sign up to request clarification or add additional context in comments.

2 Comments

as written in this doc : Executes one or multiple queries which are concatenated by a semicolon.
@gaurav: you are right But it will take care of value which contains ;
0

the mysql file is already on the server

dun use PHP ....

Linux ???

install mysql client, and run a shell like

mysql -u root -ppassword -P port_number < any.sql

Windows ???

still need to install mysql client, repeat from above


if you don't have ssh access to the server, and don't have exec right

read/prepare again the mysql file by breaking multiple queries then execute one-by-one

Comments

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.