php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16415 mysql_query() function throws away entire variable if it contains "\0"
Submitted: 2002-04-03 13:35 UTC Modified: 2002-04-04 06:25 UTC
From: kumar at chicagomodular dot com Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.1.2 OS: OpenBSD
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kumar at chicagomodular dot com
New email:
PHP Version: OS:

 

 [2002-04-03 13:35 UTC] kumar at chicagomodular dot com
actually running PHP 4.1.2-audit
_
configure command:
?'./configure' '--without-db' '--with-apache=./apache' 
'--with-mysql=/usr/local' '--with-mcrypt=/usr/local' 
'--with-zlib=/usr' '--with-db3=/usr/local' 
'--disable-debug'
_
I was doing something unnecessary with preg_replace to a 
variable --

$var = preg_replace("[\(|\)]","\0",$var);

-- before using it in an INSERT query, like so:

$SQL = "INSERT into theTable (theField) VALUES 
('".$var."')";
mysql_query($SQL,$conn);

and all I got was a blank entry for the field insert.  
Basically, the preg was stripping out "()" parenthesis and 
leaving me with the string inside the parenthesis.  the 
mysql_query must have seen the "\0" null terminator and 
thrown away the entire string.  When I changed the preg 
function to:

$var = preg_replace("[\(|\)]","",$var);

everything worked the way it was supposed to.
I know there was no good reason for me to replace with a 
null terminator but maybe this is a bug?  when I printed 
the variable out to debug I could see the string, minus the 
parenthesis, as I intended.  this is what left me confused 
for quite some time.  maybe this isn't a bug but it's 
definitely only happening in the mysql_query function, not 
PHP, so I thought I should report it.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-04 06:25 UTC] derick@php.net
Hello,

sorry, but we can't provide QA for non-official versions. It is likely that the audit version introduced this bug.
Please test php-4.2.0RC2 from www.php.net/~derick . If it still inhibits this fault, please reopen this report.

Derick
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 04:01:36 2025 UTC