Author Topic: [SOLVED] .sql with php help  (Read 357 times)

0 Members and 1 Guest are viewing this topic.

Offline bladezTopic starter

  • Irregular
  • Posts: 17
    • View Profile
[SOLVED] .sql with php help
« on: July 13, 2008, 02:30:57 AM »
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?

Offline bladezTopic starter

  • Irregular
  • Posts: 17
    • View Profile
Re: .sql with php help
« Reply #1 on: July 13, 2008, 03:56:44 AM »
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?

Offline bladezTopic starter

  • Irregular
  • Posts: 17
    • View Profile
Re: .sql with php help
« Reply #2 on: July 13, 2008, 05:49:22 AM »
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