I am trying to replace a get_result() query with bind_result() as my host won’t allow mysqlnd.
I have looked at a bunch of questions and answers here but haven’t been able to get any of them to work for me.
Here is what I was running on my local host. (I am using Slim Framework)
in DBHandler.php
/**
* Fetching all user contacts
* @param String $user_id id of the user
*/
public function getAllUsercontacts($user_id) {
$stmt = $this->conn->prepare("SELECT t.* FROM contacts t, user_contacts ut WHERE t.id = ut.contact_id AND ut.user_id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$contacts = $stmt->get_result();
$stmt->close();
return $contacts;
}
in index.php
/**
* Listing all contacts of particual user
* method GET
* url /contacts
*/
$app->get('/contacts', 'authenticate', function() {
global $user_id;
$response = array();
$db = new DbHandler();
// fetching all user contacts
$result = $db->getAllUsercontacts($user_id);
$response["error"] = false;
$response["contacts"] = array();
// looping through result and preparing contacts array
while ($contact = $result->fetch_assoc()) {
$tmp = array();
$tmp["id"] = $contact["id"];
$tmp["contactname"] = $contact["contactname"];
$tmp["contactemail"] = $contact["contactemail"];
$tmp["contactaddress"] = $contact["contactaddress"];
$tmp["contactnotes"] = $contact["contactnotes"];
$tmp["createdAt"] = $contact["created_at"];
array_push($response["contacts"], $tmp);
}
echoRespnse(200, $response);
});
This all runs great on my PC in XAMPP, but not on my shared server. I know in bind_result() you need the field names and they are the following,
id
created_at
contactname
contactemail
contactaddress
contactnotes
I have tried a few things that I found but none of them worked for me
Thanks in advance for any help!