Jump to content

mysqli statement bind_param using array or object element var


nolanpro

Recommended Posts

Why does this work:

$stmt->bind_param('s', $param);

But this does not:

$stmt->bind_param('s', $array[0]);

In this test:

$stmt = $db->prepare('select id from letters where letter = ?');
$stmt->bind_param('s', $array[0]);
$array = array('a', 'b', 'c');
$param = 'a';

$stmt->execute();
$stmt->bind_result($id);
while($stmt->fetch()) {
  echo "Id: $id\n";
}

 

When both $param and $array[0] are the same thing! "a"

 

(php 5.3, mysql 5.0)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.