Jump to content

Recommended Posts

This is my code

$stmt = $db->prepare("SELECT factory FROM offices
    WHERE id=?");
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($factory);
 
echo "<br />factory: ".$factory;

problem is there is no value being assigned to the $factory variable. when I run the query in PHPMyAdmin I get back one result, as expected. Any help would be highly appreciated 

Edited by albmed7589
Link to comment
https://forums.phpfreaks.com/topic/301475-simple-php-sql-query-help/
Share on other sites

you are missing a $stmt->fetch(); method call to retrieve the data.

 

the PDO extension is much more consistent and straight-forward to use, particularity with prepared queries. if you can, switch from using the mysqli extension to the PDO extension.

Edited by mac_gyver

LovePHP: mysqli requires the variable type to do the bind using the ? parm. Therefore the OP's code is correct as it is.

 

Mac_gyver has solved the user problem - no data was being fetched.

 

And Mac_gyver has my vote on his choice of PDO over mysqli!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.