jj20051 Posted September 13, 2010 Share Posted September 13, 2010 I'm attempting to import a mysql database backup via php unfortunately I keep getting this error: 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 'SOURCE file.sql' at line 1 Code: mysql_query("SOURCE file.sql") or die (mysql_error()); I've researched this online and this seems to be the way everyone suggests to use, unfortunately it isn't working. If it helps here is the first 4 lines of file.sql as that may be the problem for all I know: -- phpMyAdmin SQL Dump -- version 3.2.4 -- http://www.phpmyadmin.net -- Link to comment https://forums.phpfreaks.com/topic/213268-importing-a-database-via-php/ Share on other sites More sharing options...
tomz0r Posted September 13, 2010 Share Posted September 13, 2010 There is an error in you SQL code. Maybe provide that here or look through it carefully. Link to comment https://forums.phpfreaks.com/topic/213268-importing-a-database-via-php/#findComment-1110467 Share on other sites More sharing options...
jj20051 Posted September 13, 2010 Author Share Posted September 13, 2010 Here is the code, I took off the first portion which was unnecessary: Click Here I tried taking all of the sql out except the first table, still getting the same error. Link to comment https://forums.phpfreaks.com/topic/213268-importing-a-database-via-php/#findComment-1110469 Share on other sites More sharing options...
chintansshah Posted September 13, 2010 Share Posted September 13, 2010 Hey, I checked the file but it haven't any fault in file. I think you should change your logic to import by source command. $con = mysql_connect('localhost','user','pass'); $db = mysql_select_db('dbname',$con); $val = file_get_contents('file.txt'); $query = explode('-- --------------------------------------------------------',$val); foreach( $query as $k=>$v) { mysql_query($v); } This worked. let me know still you are facing problems. Link to comment https://forums.phpfreaks.com/topic/213268-importing-a-database-via-php/#findComment-1110478 Share on other sites More sharing options...
Pikachu2000 Posted September 13, 2010 Share Posted September 13, 2010 Your link is 404 - Not Found Link to comment https://forums.phpfreaks.com/topic/213268-importing-a-database-via-php/#findComment-1110480 Share on other sites More sharing options...
chintansshah Posted September 13, 2010 Share Posted September 13, 2010 I think, he got the solution and delete the file from the server. right? Link to comment https://forums.phpfreaks.com/topic/213268-importing-a-database-via-php/#findComment-1110484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.