note 39149 added to function.mysql-query
| From: | klync- at rn2 dot php dot net | Date: | Mon, 19 Jan 2004 02:05:49 +0000 |
| Subject: | note 39149 added to function.mysql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63806@lists.php.net to get a copy of this message | ||
I couldn't use mysql_query() to initialize a database the way you can dump a file in from the
command line (i.e.
mysql -u db_user -p my_database < dbfile.sql).
in the end, I had to read the file into a string:
$dbf_handle = fopen($db_file, "r");
$sql_query = fread($dbf_handle, filesize($db_file));
fclose($dbf_handle);
and then I used explode to go through each line of the dumpfile:
foreach ( explode(";", "$sql_query") as $sql_line) {
if ( $dbquery = mysql_query("$sql_line") ) {
....
Great for a db installer script.
----
Manual Page -- http://www.php.net/manual/en/function.mysql-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39149
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39149&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39149&report=yes
Search -- http://master.php.net/manage/user-notes.php