警告:mysqli_stmt :: bind_param():无效的对象或资源mysqli_stmt

时间:2018-01-15 12:59:11

标签: php mysql warnings

这是什么警告? 警告:mysqli_stmt :: bind_param():无效的对象或资源mysqli_stmt

我使用this数据库。

<?php
$conn = new mysqli('localhost','root','','new_schema');
$stmt = $conn->stmt_init();
$query = "select * from csv where rgion = ? and city like ?";
$stmt->prepare($query);
$reg = 11;
$ci = '%dg%';
$stmt->bind_param('si',$ci,$reg);
$stmt->bind_result($country,$city,$accentcity,$region,$population,$latitude,$longitude);
$stmt->execute();
echo "<table border='1'>";
while ($stmt->fetch()) {
    echo "<tr>";
    echo "<td>$country</td>";
    echo "<td>$city</td>";
    echo "<td>$accentcity</td>";
    echo "<td>$region</td>";
    echo "<td>$population</td>";
    echo "<td>$latitude</td>";
    echo "<td>$longitude</td>";
    echo "</tr>";
}
echo "</table>";

3 个答案:

答案 0 :(得分:0)

首先你在bind_param中有错误的类型序列(首先你有一个int,第二个是一个字符串)所以尊重键入一个序列

  $query = "select * from csv where rgion = ? and city like ?)";
  $stmt->prepare($query);
  $reg = 11;
  $ci = '%dg%';
  $stmt->bind_param('is',$reg, $ci);

作为建议尝试以这种方式避免字符串中的wildchar

  $query = "select * from csv where rgion = ? and city like concat('%',?,'%')";
  $stmt->prepare($query);
  $reg = 11;
  $ci = 'dg';
  $stmt->bind_param('is',$reg, $ci);

答案 1 :(得分:0)

我再次更改代码没有工作!! 警告:mysqli_stmt :: bind_param():无效的对象或资源mysqli_stmt

<?php
$conn = new mysqli('localhost','root','','new_schema');
$stmt = $conn->stmt_init();
$query = "select * from csv where rgion = ? and city like ?";
$stmt->prepare($query);
$reg = 11;
$ci = '%dg%';
$stmt->bind_param('is',$reg,$ci);
$stmt->bind_result($country,$city,$accentcity,$region,$population,$latitude,$longitude);
$stmt->execute();
echo "<table border='1'>";
while ($stmt->fetch()) {
    echo "<tr>";
    echo "<td>$country</td>";
    echo "<td>$city</td>";
    echo "<td>$accentcity</td>";
    echo "<td>$region</td>";
    echo "<td>$population</td>";
    echo "<td>$latitude</td>";
    echo "<td>$longitude</td>";
    echo "</tr>";
}
echo "</table>";

答案 2 :(得分:0)

  

你也试过了concat的建议(而且没有   %)...

我也再次测试它警告

<?php
$conn = new mysqli('localhost','root','','new_schema');
$stmt = $conn->stmt_init();
$query = "select * from csv where rgion = ? and city like concat('%',?,'%')";
$stmt->prepare($query);
$reg = 11;
$ci = 'dg';
$stmt->bind_param('is',$reg,$ci);
$stmt->bind_result($country,$city,$accentcity,$region,$population,$latitude,$longitude);
$stmt->execute();
echo "<table border='1'>";
while ($stmt->fetch()) {
    echo "<tr>";
    echo "<td>$country</td>";
    echo "<td>$city</td>";
    echo "<td>$accentcity</td>";
    echo "<td>$region</td>";
    echo "<td>$population</td>";
    echo "<td>$latitude</td>";
    echo "<td>$longitude</td>";
    echo "</tr>";
}
echo "</table>";