how can i run an sql file with multipile create commands using php without manually parsing the sql file?
I'm building a web application using PHP5.3 and Zend Framework 1.9.4. 开发者_如何转开发i have an sql file that creates and populates the relevant tables.
is there a way to install this sql file using PHP or even some component of Zend Framework ? for now i just search for the mysql client binary and install using it.
Could you explain why parsing is not wanted? If your data is such that ") ; \n
" or maybe just ") ;
" can be used as a delimiter string then you can read the entire file into a string ( file_get_contents ) and break into parts ( strtok ) in totally 3-4 lines.
( Or you could look at phpmyadmin source code if that is available to you, but that's very unwise to use like that )
For my Zend Framework projects, I do this using Ant's SQL task, so when I deploy the application using Ant, it runs the sql script to create the tables (if they don't exist). I think you could also do the same thing with phing, if you are familiar with that.
Sorry, that's not really a direct answer to your question, but if you use something like Ant it can get the job done for you.
for me it worked with explode(';',$string) then loop through resulted parts and after checking if trimmed version of the current part is not blank simply ran mysql_query() in a error catching construction (so i don't get that 'blank execution' error)
精彩评论