tags:

views:

103

answers:

4

Hi.

Im using mysql with PHP, I was just wondering if this query,

$query = "UPDATE tblName SET field='$fieldValue' WHERE field2='$fieldValue2'"
would cause an Out of Memory Error in mysql. Will this query,
$query = "UPDATE tblName SET field='".$fieldValue."' WHERE field2='".$fieldValue2."'"
consume less memory than the previous one?

Im getting this error: Out of memory (Needed nnnnnnn bytes) and its pointing to the query with the same format as the first one above.

Thanks.

+1  A: 

As far as MySQL is concerned, the two strings are the same.

How big are these values in $fieldValue and $fieldValue2? If they're multiple megabytes, attempting to allocate space for the $query variable may be exceeding your PHP memory limit - perhaps you need to up it if you're working with large data.

Amber
The values for $fieldValue and $fieldValue2 are not big. Not yet anyway. Anyways thanks, ill try increasing the limit
uji
A: 

Both strings are the same, one uses inline interpolation, the other uses string concatenation. I think your problem has to be found somewhere else.

kemp
+1  A: 

If you code like that, this will happen. Don´t code like that, please.

anddoutoi
The code posted doesn't indicate where the field values are coming from - it's quite possible that the values in the variables have already been properly pre-processed for validation+escaping.
Amber
Could be, but not likely. Call it a hunch ^^
anddoutoi
@Dav No, even in that case you are wrong. Use prepared statements. Whatever you do, just do not use string concatenation.
shylent
A: 

Well the out of memory error is probably caused by the fact that the values in those variables are simply too long. If that is the case you should look into prepared statements as those can handle MUCH bigger values than simple queries.

Ramuns Usovs