beaux1 Posted April 12, 2007 Share Posted April 12, 2007 I'm not precisely sure which section this is belong to, but I'll put it in MySQL. Basically, I want to be able to run my .SQL file from the PHP script. I know it's possible, as I've seen it been done before, examining other code except I can't exactly work out how it's done. I've googled it, but there's just so many damn ways I've seen of it being done, it confuses the hell out of me. Can anyone share their wisdom with me here? Thans Quote Link to comment Share on other sites More sharing options...
rpadilla Posted April 12, 2007 Share Posted April 12, 2007 you can parse the .sql file , you can use fopen to read it and use the semicolon as your marker on which the sql ends make sure to leave the remarks too and the spaces. check out string functions in php, to help you determin where is the start and end of the query statement. good luck. Quote Link to comment Share on other sites More sharing options...
beaux1 Posted April 12, 2007 Author Share Posted April 12, 2007 Okay, I decided to use file_get_contents : $sql = file_get_contents("sql.sql"); // End Retrieve SQL Query if (mysql_query($sql)) { Now, my sql.sql file works if I import it into phpMyAdmin, or if I only have one of the two SQL Queries in here. Anyway I can somehow format them so it will read the both of them and work? CREATE TABLE admin ( ID int(7) NOT NULL auto_increment, username varchar(15) default NULL, password varchar(32) default NULL, PRIMARY KEY (ID), UNIQUE KEY id (ID) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1; CREATE TABLE posts ( ID int(7) NOT NULL auto_increment, name varchar(15) default NULL, date varchar(100) default NULL, subject varchar(100) default NULL, PRIMARY KEY (ID), UNIQUE KEY id (ID) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Quote Link to comment Share on other sites More sharing options...
fenway Posted April 12, 2007 Share Posted April 12, 2007 Not exactly, since AFAIK mysql_query will only run a single one.... and parsing it will be annoying at best. Quote Link to comment Share on other sites More sharing options...
beaux1 Posted April 12, 2007 Author Share Posted April 12, 2007 Ah, I see. So are the any other ways around this? Quote Link to comment Share on other sites More sharing options...
fenway Posted April 12, 2007 Share Posted April 12, 2007 Well, if you can GUARANTEE that new statements will start on a newline and be preceded by a semi-colon, you could easily make an array out of them, and send them to mysql_query() one at a time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.