Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2013
    Posts
    1

    Unanswered: returning 0 rows, but phpMyAdmin SQL returns plenty!

    Code:
    	$query = "SELECT * FROM employees WHERE 1";
    	
    	// Handle keeps coming back NON-NULL
    	$handle = mysql_query($query);
        
        // These both report nothing.
        $errno = mysql_errno();
        $error = mysql_error();
    		
    	// Reports 0.
    	$nNumRows = @mysql_numrows($handle); 
    
    	// $row keeps coming back NULL.
    	$row = mysql_fetch_array($handle, MYSQL_ASSOC);

    Here's the strange part -- if I paste the SQL code into phpMyAdmin, I get 2 rows, no problem.

    How can this be explained?

    NOTE: My database query isn't literally that simple. It has 1 join statement. But that shouldn't matter, since phpMyAdmin likes my query just fine, right?

    It can't be a problem with my SQL code, because when I paste it into a text file, remove the PHP code (variables, quotes, semicolons, etc.) and paste it into phpMyAdmin, it runs and returns 2 rows. I don't change any of the SQL code; I just fill in the variables with a sample keyword.

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Post back the exact results of
    Code:
    echo $query;
    die()
    Test them in phpMyAdmin too.
    George
    Home | Blog

  3. #3
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    I would add error checking into your code. Anywhere when you issue a mysql_ function call I would include or die(mysql_error());

    Code:
    	$query = "SELECT * FROM employees WHERE 1";
    	
    	// Handle keeps coming back NON-NULL
    	$handle = mysql_query($query) or die(mysql_error());
        
    	// Reports 0.
    	$nNumRows = @mysql_numrows($handle) or die(mysql_error()); 
    
    	// $row keeps coming back NULL.
    	$row = mysql_fetch_array($handle, MYSQL_ASSOC) or die(mysql_error());
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •