这个准备好的陈述怎么了

时间:2011-06-29 19:48:18

标签: php mysql mysqli mysql-parameter

我有一个刚刚在几小时前学到的准备好的陈述,但我总是作为回报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我试过了所有的事情, 但是,如果我这样做,没有准备好的声明就行了

$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>";

我准备好的陈述中是否有错误?

2 个答案:

答案 0 :(得分:3)

$stmt->execute;

这是一种方法。它应该是:

$stmt->execute();

答案 1 :(得分:0)

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