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 -- Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 13, 2010 Share Posted September 13, 2010 Your link is 404 - Not Found Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.