Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. PHP call to mysqli_query returns null (as expected) but I don't seem to be able to detect it

PHP call to mysqli_query returns null (as expected) but I don't seem to be able to detect it

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phpdatabasequestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jonathan Davies
    wrote on last edited by
    #1

    My SELECT query works fine when I've got records. Whether there are no records, or not in the result set I get a warning

    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given

    I've tested the result agains

    FALSE, NULL, null

    (both null and NULL seem to be used in examples and the manual)and calling

    is_null($result)

    but I don't pick it up. Why? I just want to be able to differ between technical failure and return of zero records.

    $query = 'SELECT CommentId, ParentId, Subject, Name, DATE_FORMAT(TimeStamp,"%k::%i %d-%m-%Y (GMT)"), Comment FROM commentdata WHERE ArticleId = ' . $ArticleId . ' ORDER BY COALESCE ( ParentId, CommentId)';

        $result = mysqli\_query($connect, $query);
        
        if(TRUE == $result)
        {
            echo 'TRUE returned on query for data: ' . mysqli\_error($connect) . '  
    

    ';
    }

        if(FALSE == $result)
        {
            echo 'FALSE returned on query for data: ' . mysqli\_error($connect) . '  
    

    ';
    mysqli_close($connect);
    die("Connection closed after FALSE returned on query for data: " . mysqli_error($connect));
    }

        if(NULL == $result))
        {
            echo 'NULL returned on query for data: ' . mysqli\_error($connect) . '  
    

    ';
    mysqli_close($connect);
    die("Connection closed after NULL returned on query for data: " . mysqli_error($connect));
    }

        if(null == $result))
        {
            echo 'null returned on query for data: ' . mysqli\_error($connect) . '  
    

    ';
    mysqli_close($connect);
    die("Connection closed after null returned on query for data: " . mysqli_error($connect));
    }

        if(is\_null($result))
        {
            echo 'NULL returned on query for data: ' . mysqli\_error($connect) . '  
    

    ';
    mysqli_close($connect);
    die("Connection closed after NULL returned on query for data: " . mysqli_error($connect));
    }

        /\* determine number of rows in result set \*/
        $rowcount = mysqli\_num\_rows($result);
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups