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

wixjitnu  于 2021-06-24  发布在  Mysql
关注(0)|答案(3)|浏览(392)

这是什么警告?警告: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('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>";
kh212irz

kh212irz1#

您也尝试过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>";
krcsximq

krcsximq2#

首先,您在bind_param中有错误的类型序列(第一位是int,第二位是string),所以请尊重类型序列

$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);
2ekbmq32

2ekbmq323#

我又改了代码没用!!警告: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>";

相关问题