bladez Posted July 13, 2008 Share Posted July 13, 2008 i would like to execute a .sql file thru php.. without using telnet / mysql console. i have tried Source <filename.sql> << doesnt work i am not sure why .. basically i am running on windows box.. and i would like to make it compatible to work on linux for also ... therefore i would wan to use absolute path .. does SOURCE accept relative paths ? such tat installation/filename.sql ?? i have also tried LOAD DATA INFILE... bla bla bla.. again absolute path dun wan .. is there anyway i execute .sql file like how we open file. or more like execution thru relative path mayb say a thru a web url ? or any better idea? Quote Link to comment Share on other sites More sharing options...
bladez Posted July 13, 2008 Author Share Posted July 13, 2008 i got the solution but now am hving another problem...sorry... i am using : $connect = mysql_connect($_POST['dbhost'],$_POST['username'],$_POST['password']); if ($con !== false){ if ($_POST['dbcreate'] == 1){ $sqlFileToExecute = "UCMSSQLCreateDB.sql"; $f = fopen($sqlFileToExecute,"r+"); } else{ $sqlFileToExecute = "UCMSSQL.sql"; $f = fopen($sqlFileToExecute,"r+"); $db = mysql_select_db($_POST['dbname']); } $sqlFile = fread($f,filesize($sqlFileToExecute)); $sqlArray = explode(';',$sqlFile); foreach ($sqlArray as $stmt) { if (strlen($stmt)>3){ $result = mysql_query($stmt); if (!$result){ $sqlErrorCode = mysql_errno(); $sqlErrorText = mysql_error(); $sqlStmt = $stmt; break; } } } if ($sqlErrorCode == 0){ echo "Installation was finished succesfully!<br><br>"; } else { echo "An error occured during installation!<br>"; echo "Error code: $sqlErrorCode<br>"; echo "Error text: $sqlErrorText<br>"; echo "Statement:<br/> $sqlStmt <br><br>"; } } else{ echo "Connection to SQL File Failed!"; } mysql_close($connect); it works.. but now am hving another problem is tat how do i include the table prefix tat i prefer.. instead of compiled during sql export? Quote Link to comment Share on other sites More sharing options...
bladez Posted July 13, 2008 Author Share Posted July 13, 2008 its ok i manage to find the solution myself... Here is how i do it.. Jus thought of sharing i use preg_replace () thanks guys .. anyway moderator u can close this topic 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.