Forum Moderators: coopster

Message Too Old, No Replies

Howto Load SQL from a file

         

emon

6:35 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



Howto load sql file(external) with php ...

>>index.html
<form method=post action='test.php'>
<input type=file name=file><br>
<input type=submit value=DO>
</form>

>>test.php
$sql = file_get_contents($_FILES['file']);
$sql = trim($sql);

mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query($sql);

eelixduppy

8:10 pm on Jul 12, 2007 (gmt 0)



Upload the file how you would normally, described here in handling file uploads [us.php.net]. Then you can use mysql's mysqlimport [dev.mysql.com] utility to import the data from that file. Once you are finished with that you should unlink [php.net] the SQL file.

Just a note about the file upload. You should keep the file below the web root.