Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi,
I am having trouble using bind variables in prepared statements with mysqli.
I have:
PHP version: 5.1.4
Linux distro: Kubuntu dapper drake
Mysql: 4.1.12
This first set of code does not use bind variables and works as expected:Code: Select all
$sql = "SELECT count(*) as TOTAL from users where id = 1";
$stmt=$mysqli->prepare($sql);
$stmt->bind_result($count);
$stmt->execute();
$stmt->fetch();
echo "Count is: ".$count."<br/>";
$stmt->close();The second set of statements, displays Count is: 0, when I thought
it is the same query as the first one:
Code: Select all
$sql_bind = "SELECT count(*) as TOTAL from users where id = ?";
$stmt=$mysqli->prepare($sql_bind);
$id = 1;
$stmt->bind_param('i', $id);
$stmt->bind_result($count);
$stmt->execute();
$stmt->fetch();
echo "Count is: ".$count."<br/>";feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]