简体   繁体   中英

PHP prepare statement for COUNT() with condition for one result

Counting number of failed login attempt for last 2 hours with IP addresses. But following bind_param code section showing error.

Call to a member function bind_param() on boolean

Here is the code:

 $ipp = $_SERVER['REMOTE_ADDR'];
 $flood_count = $mysqli->query("SELECT COUNT(f_ip) FROM flood WHERE f_ip = ? 
   AND f_time > NOW()-INTERVAL 2 HOUR ");
                 $flood_count->bind_param('s',$ipp);
                 $flood_count->execute();
                   $flood_count->store_result();
                  $flood_count->bind_result($count_data);                   
                  $flood_count->fetch();
                  echo $count_data;

Testing it on local host where ip address is '::1'

on line 2: $mysqli->prepare( ..... )

query tries to execute directly. prepare is what you need to bind the parameters

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM