Forum Moderators: coopster

Message Too Old, No Replies

mySQL not inserting all data

         

tryant4d

2:55 am on Mar 7, 2006 (gmt 0)

10+ Year Member



Hi folks.

I'm using php to dynamically create a query from an array. When the query is run, it doesn't always insert all of the data. Some of the last columns are ignored. It happens on very long inserts... with over 50 columns in the table.

Is it timing out? Too big for a buffer?

How does one get around this?


$connection = mysql_connect($db, $db_user, $db_pass) or die('1 '.mysql_error());
mysql_select_db($db_2, $connection) or die('2 '.mysql_error());
/*** constructing query that inserts data into table ***/
$query = "INSERT INTO ".$sectionName." (coID,";
for($i=1;$i<=count($_SESSION['currentSection'])-1;$i++){
$query = $query.$sectionNumber."_".$i.", ";
}
$query = $query.$sectionNumber."_".$i.")";
$query = $query." VALUES (\"".md5($_SESSION['setup']['coname'])."\",\"";
for($i=1;$i<=count($_SESSION['currentSection'])-1;$i++){
$query = $query.$_SESSION['currentSection'][$i]."\",\"";
}
$query = $query.$_SESSION['currentSection'][$i]."\")";
/*** cleaning query text ***/
$query = validateQuery($query);
if($result = mysql_query($query, $connection)){
mysql_close($connection);
...

omoutop

12:57 pm on Mar 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Check your data. Validate your sessions (they may need stripslaches, htmlspecialchars etc to clean them of unwanted elements). 50 colums are not enought to time-out a query (i have run queries with 400 colums updates/inserts in one table and no time out).

Try to print/echo the query to see where it stops inserting data (debug).

coopster

12:58 pm on Mar 7, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, tryant4d.

I see you are monitoring the errors on a connection, but not on the actual query. Have you tried monitoring the query for errors to see if any are returned? I guess if you are INSERTing partial data then the query must not be failing, just not working correctly.

I would dump the statement to the browser to see what it looks like. There is a Troubleshooting PHP [webmasterworld.com] thread in our PHP Forum Library [webmasterworld.com] that describes how to do this.

<added>
omoutop and I are thinking along the same lines here, thanks, omoutop!
</added>

dmmh

1:10 pm on Mar 7, 2006 (gmt 0)

10+ Year Member



debugging, the nightmare of any coder :D
good luck :)

tryant4d

3:13 am on Mar 8, 2006 (gmt 0)

10+ Year Member



Yes, a nightmare. You were all right. The query was being constructed wrong when some of the array elements were null.

Oops.

And thanks.

Tom