From: chippy at acornsrus dot com Operating system: Linux PHP version: 4.3.9 PHP Bug Type: MySQL related Bug description: mysql_query() fails when query works directly in MySQL
Description: ------------ When sending the MySQL query through the mysql_query() function, MySQL does not send back a result set. But when echoing out the $sql statement and running it directly into the MySQL database via PHPMyAdmin or another tool, the query comes back with the intended results. Also, running a mysql_error(); outputs nothing. So this lead me to believe it was a bug in PHP. Reproduce code: --------------- define("DB_ADDY","localhost"); define("DB_USER","icesnak_eqitems"); define("DB_PW","trademasters"); define("DB_DB","icesnak_eqitems"); function find_item($types,$terms){ if((!empty($types))&&(!empty($terms))){ $types[] = "stock"; $terms[] = "instock"; $dblink = mysql_connect(DB_ADDY,DB_USER,DB_PW); mysql_select_db(DB_DB,$dblink); $sql = "SELECT * FROM `items` WHERE `". $types[0]. "` LIKE '%". $terms[0]. "%' ORDER BY `itemname` ASC"; $result = mysql_query($sql,$dblink); if(mysql_num_rows($result)){ echo 'Something'; } else { echo 'Nothing'; } } } Expected result: ---------------- I would expect to get the output of "Something" since there are multiple rows in the database that match the search criteria. I think this issue has to do with the use of the "%" wildcard character... Actual result: -------------- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mystuff/public_html/core/core/EQItems.php on line 73 Nothing -- Edit bug report at http://bugs.php.net/?id=31081&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31081&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31081&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31081&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31081&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31081&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31081&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31081&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31081&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31081&r=support Expected behavior: http://bugs.php.net/fix.php?id=31081&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31081&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31081&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31081&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31081&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31081&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31081&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31081&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31081&r=float MySQL Configuration Error: http://bugs.php.net/fix.php?id=31081&r=mysqlcfg