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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.