Reputation: 362
I have read about 15 posts on here so far regarding issues like this none of which have been able to help me.
I have the following code:
$stmt3 = $mysqli->prepare("SELECT cc.name, cc.company, cc.email FROM (`case_contacts` cc) WHERE cc.case_id=? AND cc.end_date IS NULL");
if (is_object($stmt3)) {
$stmt3 -> bind_param("i", $case_id);
} else {
die('Connection issue');
}
$stmt3 -> execute();
$stmt3 -> bind_result($name, $company, $email);
while ($stmt3->fetch()) {
When I execute it advises "Connection issue". However just before $stmt3
I can var_dump $mysqli
quite happily.
I have manually entered the query into both phpmyadmin and an online query checker and both confirm that it is valid.
I have checked the permissions of the user, they are all fine. In fact I am in the process of re-writing queries from mysql to mysqli and wantedto use prepared statements. So the database user is the same. I have had no issues with other prepared statements more complex that this so I am really at a loss to what I am missing.
I have even overkilled the '`' quote wrap on the statement as I know I should on every query!
Any advice, debugging tips would be great. I have had a look around and the ones I have found are not providing an output.
Upvotes: 1
Views: 249
Reputation: 7791
mysqli_stmt::prepare ( string $query )
return TRUE
or FALSE
read more at:
You can use this example:
<?php
$mysqli = mysqli_connect('localhost', 'root', 'admin', 'test');
$case_id = 603;
$sentence = $mysqli->stmt_init();
if($sentence->prepare("SELECT name, company, email FROM case_contacts WHERE case_id = ? AND end_date IS NULL")) {
$sentence->bind_param("i", $case_id);
$sentence->execute();
$sentence->bind_result($name, $company, $email);
while ($sentence->fetch()) {
echo $name . ' - ' . $company . ' - ' . $email;
}
}
Upvotes: 1