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
Share on other sites

sql not successful: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '; insert into admin_users values( '3' , 'admin' , '558341344316

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.