Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-18-2012, 09:48 AM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 611
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Query not throwing proper error

I have the following code that is not throwing an error like I am used to...

PHP Code:
    // Build query.
    
$q2 "SELECT MAX(comment_no) AS lastCommentNo
            FROM comment
            WHERE article_id=?"
;

    
// Prepare statement.
    
$stmt2 mysqli_prepare($dbc$q2);

    
// Bind variable to query.
    
mysqli_stmt_bind_param($stmt2'i'$articleID);

    
// Execute query.
    
mysqli_stmt_execute($stmt2);

    
// Store results.
    
mysqli_stmt_store_result($stmt2);

    
// Check # of Records Returned.
    
if (mysqli_stmt_num_rows($stmt2)==1){
        
// Maximum Found.

        // Bind result-set to variables.
        
mysqli_stmt_bind_result($stmt2$lastCommentNo);

        
// Fetch record.
        
mysqli_stmt_fetch($stmt2);

        
// Increment CommentNo.
        
$commentNo $lastCommentNo 1;

    }else{
        
// Maximum Not Found.
        
$_SESSION['resultsCode'] = 'COMMENT_MAXIMUM_NOT_FOUND_2049'

Normally to test the "Error Branch" of my code above, I would change $articleID to $articleID2, thus breaking my query and launching the ELSE branch of my code with the Error-Message.


The problem seems to be that $articleID2=0 and so my query returns a NULL for the MAX() which technically counts as a row being returned?!

Follow me?!

That isn't the behavior I am looking for.



Debbie
doubledee is offline   Reply With Quote
Old 06-18-2012, 12:32 PM   PM User | #2
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 575
Thanks: 15
Thanked 64 Times in 64 Posts
Arcticwarrio is on a distinguished road
how about
PHP Code:
$q2 "SELECT MAX(comment_no) AS lastCommentNo
            FROM comment
            WHERE article_id='debbie'"

Arcticwarrio is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:20 AM.


Advertisement
Log in to turn off these ads.