Reputation: 41
What is this warning? Warning: mysqli_stmt::bind_param(): invalid object or resource mysqli_stmt
my use this Database.
<?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>";
Upvotes: 0
Views: 2747
Reputation: 41
you have tried with the concat suggestion too (and the string without %)??
I also tested it again warns
<?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>";
Upvotes: 0
Reputation: 41
I changed the code again did not work!! Warning: mysqli_stmt::bind_param(): invalid object or resource 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>";
Upvotes: 0
Reputation: 133370
First you have wrong sequence of type in bind_param (first place you have an int, second a string) so respect type an sequence
$query = "select * from csv where rgion = ? and city like ?)";
$stmt->prepare($query);
$reg = 11;
$ci = '%dg%';
$stmt->bind_param('is',$reg, $ci);
and as a suggestion try avoid the wildchar in string this way
$query = "select * from csv where rgion = ? and city like concat('%',?,'%')";
$stmt->prepare($query);
$reg = 11;
$ci = 'dg';
$stmt->bind_param('is',$reg, $ci);
Upvotes: 1