danlatario Posted November 26, 2007 Share Posted November 26, 2007 Hi All, I been stuck on a problem for a bit now and cant really find an answer so I hope someone knows here. I have the following code: function db_query_prepare($dbh, $sql, $args) { $dbst = mysqli_prepare($dbh, $sql); if(!$dbst) {return 0;} foreach($args as $arg) { mysqli_stmt_bind_param($dbst, "i", $arg); } mysqli_stmt_execute($dbst); mysqli_stmt_store_result($dbst); return $dbst; } $result = db_query_prepare($db, "SELECT firstname FROM profile WHERE profileID = ? AND statusID = ? LIMIT 1", array(55, 3)); the above was taken from the book: php cookbook2 (For now assume all values are integers) I have code very similar to the that above, my question is simple, is this code correct? I can get the code to work with a single ? (placeholder), but it throws a "Number of variables doesn't match number of parameters in prepared statement in .." warning/error, I know there is a form of the function that is as follows: mysqli_stmt_bind_param($dbst, 'ii', 55, 54 ) But my problem is I may not know the parameters in advance so I just want to pass db_query_prepare the sql and needed values in an array? looking at the above code taken from the book implies that it indeed can be done, but I just get the same error, I have also tried implode, to return a string 1,2,3 etc, but still I get the above error? I have done a bit of searching, and there are reported bugs giving the same error, but I have upgraded libraries as suggested but still to no avail? MySqli details: Client version: 50045 Server version: 50041 The only solution I have found is to build a string and execute it using eval! Link to comment https://forums.phpfreaks.com/topic/78920-mysqli_stmt_bind_param-help-please/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.