Project Beehive ForumNull values from query functions.

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Peter (BOUGHTONP)  
 To:  Matt     
42762.1 
Hey Matt,

I'm getting errors with PHP 7.4.15 and MariaDB 10.5.9 on Debian.

For example, function thread_has_attachments in include/thread.inc.php - line 1365 should return false but doesn't.
Same situation for stats_get_most_popular_birthday in include/stats.inc.php line 1499

In both cases, the queries correctly return no values, but the if condition is failing:

if (!($result = $db->query($sql))) return false;

Is this a PHP change, a DB driver issue, or something else?

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Peter (BOUGHTONP)     
42762.2 In reply to 42762.1 
Seems to work if I add "->num_rows", i.e:
if (!($result = $db->query($sql))->num_rows) return false;

The docs suggest this works in PHP 5, so a mass search-replace won't break backwards compatibility?

https://www.php.net/manual/en/mysqli-result.num-rows.php

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Peter (BOUGHTONP)     
42762.3 In reply to 42762.2 
> Seems to work if I add "->num_rows", i.e:

Except for UPDATE queries which return booleans instead of objects, such as in the user_logon function.

Stupid PHP.

Also, checking a few of the 391 matches, some of them already have additional num_rows checks on separate rows.

Not sure if it'll be easier to click every link and fix them as they crop up, but I haven't had lunch yet so I'm doing that first.

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
42762.4 In reply to 42762.3 
What was for lunch?
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
42762.5 In reply to 42762.4 
A traditional Italian dish.
0/0
 Reply   Quote More 

 From:  koswix  
 To:  Peter (BOUGHTONP)     
42762.6 In reply to 42762.5 
What was on top of it?

 ▪                    
             ┌────┐    ┌────┐                      
          │    │    │    │ ▪                    
          │    └────┘    │                      
          │   ──┐  ┌──   │ ▪                    
   ┌──────┤    ▪    ▪    │                      
  ┌┘      │              │ ▪                    
┌─┤       └──┐  │  │  ┌──┘                      
│ │          │ ││  ││ │   ┌─┐                   
│ │          └─┼┤  └┴─┴───┘ │                   
│ │           ─┘│           │                   
│ │   ┌──────┐  └┬──────────┘                   
  │   │      │   │                              
  │   │      │   │                              
  └───┘      └───┘                              
If Feds call you and say something bad on me, it may prove what I said are truth, they are afraid of it.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  koswix     
42762.7 In reply to 42762.6 
Mature cheddar cheese - if you believe the packaging - but always an insubstantial amount, and the necessary stirring prevents any noticable taste that those few grams might impart.
0/0
 Reply   Quote More 

 From:  Matt  
 To:  Peter (BOUGHTONP)     
42762.8 In reply to 42762.2 
$db->query (which is a wrapper around mysqli::query) can return false, so adding a call to ->num_rows to it won't always work (as you now already know), but you could check for $result->num_rows afterwards, e.g.:
 
Code: 
if (!($result = $db->query($sql))) return false;

if ($result->num_rows === 0) return false;
0/0
 Reply   Quote More 

Reply to All    
 

1–8

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2021 Project Beehive Forum

Forum Stats