简体   繁体   中英

Whats wrong with this prepared statement

i have a prepared statement just learned few hours ago but i get always as return 0

$ip = $data 
$stmt = $mysqli->prepare("SELECT counter_ip 
                            FROM counter_out 
                           WHERE counter_ip = ?");
$stmt->bind_param('s', $ip);
$stmt->execute;
$stmt->bind_result($r_ip); 
$stmt->fetch();
echo "<pre>";
echo $r_ip;
echo "</pre>";

bind_result i tried all idbs, But when i do it this way without prepared statement it works

$sql = "SELECT counter_ip 
              FROM counter_out 
             WHERE counter_ip = '$ip'";
$result = $mysqli->query($sql);
$dupecheck = $result->fetch_assoc();
echo "<pre>";
echo $dupecheck[counter_ip];
echo "</pre>";

Do i have an error in the prepared statement?

$stmt->execute;

This is a method. It should be:

$stmt->execute();
$mysqli->prepare("SELECT counter_ip FROM counter_out WHERE counter_ip = :s");

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