开发者

PHP variables in mysql queries

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 o开发者_StackOverflow中文版ne above.

Thanks.


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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜