Re: Import .sql file via PHP



Tim Van Wassenhove пишет:
On 2005-05-30, Jamie Meyers <gtg061q@xxxxxxxxxxxxxxx> wrote:

Nevermind, I decided to parse the .sql file and create the query there. I do not think there is any way to import the .sql file via php. Thanks anyways. And if anyone would like this script after I fix it up a little more, let me know.


Assuming each instruction is on a line.. (untested)

$db = mysql_connect(....);
mysql_select_db(....);

$fp = fopen('somefile.sql', 'r');
while($fp != feof())
{
  $line = fread($fp, 2048);
  $line = mysql_real_escape_string($db, $line);
  mysql_query($line);
}
fclose($fp);


I guess it will NOT working, because of line can be much more than 2048 bytes, or it can be BLOB or another..
Or, can be comment multi line. your script will failed.
.




Relevant Pages

  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... This is why I am thinking about rewriting my whole script in a C language. ... Perhaps there are different methods I could be using to speed up execution. ...
    (php.general)
  • Re: How to Add a Feeback Form
    ... I saw nothing in that script that indicates where the form is e-mailed to so ... Greg Maxey/Word MVP ... PHP or not. ... have the support available yet. ...
    (microsoft.public.frontpage.programming)
  • How best to show PHP source? (was: One page, multiple submit buttons)
    ... script to add to the top of a PHP script to enable showing its ... Maybe anybody submitting their own PHP code for critique here ... Anything posted to a newsgroup is a "snapshot" of what the ... there ought to be a FAQ for this ...
    (comp.lang.php)
  • Re: Bug in #! processing - "pear broken on current"
    ... on the cvs-src mailing list...] ... script is due to the change in parsing I committed on May 28th. ... php would have been started up with: ... /usr/bin/env could be used to fix this, once I write up that change... ...
    (freebsd-arch)
  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... thinking about rewriting my whole script in a C language. ... execution of the code. ...
    (php.general)