Jump to content

a problem with semicolon in sql file


babak83

Recommended Posts

HI , I have written small code to generate backup from a mysql Database and save as a sql file, It workds great and no problem till here , but when I am trying to restore the sql file I get error in mysql syntax (I think it is because of existing semicolons in the sql file) I put the sql file content into a variable $sql for exmple and try mysql_query($sql) , How may I solve this prob ?

 

this is the code :

 

  $file = fopen($filename,"r");

  $line_count = load_backup_sql($file);

  fclose($file);

  echo "lines read: ".$line_count;

  function load_backup_sql($file) {

    $line_count = 0;

    $db_connection = db_connect();

    mysql_select_db (db_name()) or exit();

    while (!feof($file)) {

      $query = NULL;

      while (!feof($file)) {

      $query .= fgets($file);

      }

 

      if ($query != NULL) {

        $line_count++;

        mysql_query($query) or die("sql not successful: ".mysql_error());

      }

    } 

    return $line_count;

  }

 

  function db_name() {

      return ("db_name");

  }

 

  function db_connect() {

    $db_connection = mysql_connect("localhost", "user", "pass");

    return $db_connection;

  } 

Link to comment
https://forums.phpfreaks.com/topic/61681-a-problem-with-semicolon-in-sql-file/
Share on other sites

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.