babak83 Posted July 25, 2007 Share Posted July 25, 2007 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 More sharing options...
plutomed Posted July 25, 2007 Share Posted July 25, 2007 What is the error you get? Link to comment https://forums.phpfreaks.com/topic/61681-a-problem-with-semicolon-in-sql-file/#findComment-307041 Share on other sites More sharing options...
babak83 Posted July 25, 2007 Author Share Posted July 25, 2007 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 https://forums.phpfreaks.com/topic/61681-a-problem-with-semicolon-in-sql-file/#findComment-307042 Share on other sites More sharing options...
babak83 Posted July 26, 2007 Author Share Posted July 26, 2007 Isn't there any response ?? ??? Link to comment https://forums.phpfreaks.com/topic/61681-a-problem-with-semicolon-in-sql-file/#findComment-307774 Share on other sites More sharing options...
redarrow Posted July 26, 2007 Share Posted July 26, 2007 post your insert function Link to comment https://forums.phpfreaks.com/topic/61681-a-problem-with-semicolon-in-sql-file/#findComment-307810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.