You are here: Re: [PHP] novice: how to run .sql script from php? « PHP « IT news, forums, messages
Re: [PHP] novice: how to run .sql script from php?

Posted by Rory Browne on 05/27/05 18:04

I'm assuming that the .sql file consists of a list of MySQL queries,
that when performed sequentially will set up your system.

That being the case, the perfered way ot install the thing is to do a
'mysql [host/username/password parameters] < file.sql'.

I believe you can also run file.sql scripts using phpMyAdmin.

If you were to define a mysql_run_script() function, it would look a
bit like the following:

<?pseudo_code

function mysql_run_script($file){

$sql = file_get_contents($file);

$queries = split_sql_into_individual_sql_queries($sql);

foreach($queries as $query){
mysql_query($query);
}

}

?>

Come to think of it, you could turn the above pseudo code into valid
php code, by defining the split_sql_into_individual_sql_queries()
function. This would involve splitting by ';', taking into account the
possibility that ';' may occur in the middle of a string.

Check out the code for phpmyadmin, or phpbb(db backup/recover
feature), for a better idea.

On 5/27/05, tony yau <tony.yau@emigen.co.uk> wrote:
> Hi All,
>
> I got this .sql script that setup the whole db schema, I can run
> mysql.exe to run on my pc but when it goes to a hosting company's server I
> don't have that command!
>
> So I tried to include("setup.sql") into a string and send that as one
> long sql query. BUT I need to get rid of all the comment lines first in the
> script!!
>
> can someone give me a better idea of doing this.
> (there must be an equivalent php function like
> mysql_run_script("setup.sql"))
>
>
> thanks
> --
> Tony Yau
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация