MySQL not playing ball

Soldato
Joined
4 Jan 2004
Posts
20,802
Location
¯\_(ツ)_/¯
Ok, I've got this loop here that I've done in PHP. Now $filesarr is a huge array with 30,000 or so lines in.

Code:
$ca = 0;
$climit = (count($filesarr));
while ($ca < $climit) {
	list($file,$fmt,$fsz)=explode('|',$filesarr[$ca]);
	$filename = substr(strrchr($file, '\\'), 1);
	$path = str_replace("\\", "/", (substr($file, 0, -(strlen($filename)))));
	echo $path.'<BR>';
	$query = "INSERT INTO filelist (uid, path, filename, size, date) VALUES ('".$ca."', '".$path."', '".$filename."', '".$fsz."', '".$fmt."')";
	mysql_query($query) or die ('Error, insert query failed on '.$ca.', '.$path.', '.$filename.', '.$fsz.', '.$fmt); //this is where it all goes wrong
	$ca++;
}

Now, This while loop simply takes each line, splits it up, and attempts to add it to a table in my database. Now this is my first time with SQL, and what is weird about this is that it adds around 33 lines or so, then craps out (Error, insert query failed) :(

Normally things work or they don't... What am I doing wrong here? am I trying to add too many entries to my table in one go?
 
Illegal character in the table, max number of connections used?
Could possible be one of them.. :D

Edit: Might be easier to explain, since the 1st 33 queries go alright, I'm assuming its a character that shouldn't be there. Have a double check at the error produced, maybe echo the $query.
I doubt its the max number of connections, but its an option...
 
Last edited:
This is from the problem line:

echo of $query:
INSERT INTO filelist (uid, path, filename, size, date) VALUES ('33', 'I:/-=slsk-mirror=-/', '01 - Olive - You're Not Alone (Breaks Mix).mp3', '12010057', '1166835653')

echo of this lovely thing
mysql_query($query) or die (mysql_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 're Not Alone (Breaks Mix).mp3', '12010057', '1166835653')' at line 1

It's the ' in the filename that is causing the problem... I should be able to get round this with some PHP jiggerypokemy. :) I've already had to substitute backslashes with forwardslashes. Thanks!
 
Last edited:
Back
Top Bottom