0

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.

3 Answers 3

1

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 )

Sign up to request clarification or add additional context in comments.

2 Comments

actually it seems that you are correct, i can divide the sql file by the delimiter ; and run each command individually. the problem is that sometimes ';' can show up in comments or in texts in some tables. how can i do a proper parsing ?
For strtok() a delmiter need not be a single character, but can be a string. Hence ");\n" will separate at only those places where a line separates 2 queries ending with a semi-colon. Try some small sample before running the full file. It is worth learning by trial-and-error because it is totally 3-4 lines and you will learn something about parsing general text which is a useful skill to have. Try it out, it will be useful.
1

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.

1 Comment

thanks i'll take a look and see if these components will implement nice with my application.
1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.