theHack
theHack

Reputation: 2014

run mysql.sql using php

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...

Upvotes: 0

Views: 111

Answers (2)

Daric
Daric

Reputation: 16769

You could do this

$query=file_get_contents($file);

$mysqli->multi_query($query);

mysqli::multi_query can do the job.

Upvotes: 2

ajreal
ajreal

Reputation: 47311

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

Upvotes: 0

Related Questions