Twister1004 Posted September 30, 2011 Share Posted September 30, 2011 Hey everyone, I have an SQL file called "Cype.sql" and I was wanting to have it run when the install feature is going on. However I can't seem to figure out why exactly the code is not working. is it possible to have it run without getting too in depth the PHP coding? I'm not OOP Literate yet. //Connection is opened //While in installation file $sqlFile = "Cype.sql"; if(!file_exists($sqlFile)){ echo "File not found"; } else{ $openFile = fopen($sqlFile, "r"); $tryQuery = mysql_query($openFile); } Now obviously, I'm not the best coder. I've been out of the works of PHP for quite some time now as well. However, I have researched it and found no answers to my issue. Any help would be greatly appreciate. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/248193-running-an-sql-file-and-having-php-execute-it/ Share on other sites More sharing options...
Buddski Posted September 30, 2011 Share Posted September 30, 2011 Currently, you are only opening the file. You arent telling PHP to read it.. file_get_contents() will read the contents of a file for you. Quote Link to comment https://forums.phpfreaks.com/topic/248193-running-an-sql-file-and-having-php-execute-it/#findComment-1274460 Share on other sites More sharing options...
Twister1004 Posted September 30, 2011 Author Share Posted September 30, 2011 Thank you very much Buddski! Now for another question: is there a way for the mysql_query to execute multiple SQL querys in one file? Quote Link to comment https://forums.phpfreaks.com/topic/248193-running-an-sql-file-and-having-php-execute-it/#findComment-1274471 Share on other sites More sharing options...
Buddski Posted September 30, 2011 Share Posted September 30, 2011 mysql_query does not support multiple queries. You will have to loop through each query in your file and run them individually. Quote Link to comment https://forums.phpfreaks.com/topic/248193-running-an-sql-file-and-having-php-execute-it/#findComment-1274473 Share on other sites More sharing options...
Twister1004 Posted September 30, 2011 Author Share Posted September 30, 2011 Now onto figuring that out! Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/248193-running-an-sql-file-and-having-php-execute-it/#findComment-1274477 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.