php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31081 mysql_query() fails when query works directly in MySQL
Submitted: 2004-12-14 04:52 UTC Modified: 2004-12-14 09:11 UTC
From: chippy at acornsrus dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.3.9 OS: Linux
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: chippy at acornsrus dot com
New email:
PHP Version: OS:

 

 [2004-12-14 04:52 UTC] chippy at acornsrus dot com
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-14 09:11 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Try to add some error checking too...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 02:01:29 2024 UTC