Jump to content

[SOLVED] .sql with php help


bladez

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/114505-solved-sql-with-php-help/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.