开发者

Cannot pass parameter by reference PHP prepared statement problem

开发者 https://www.devze.com 2023-02-11 14:31 出处:网络
I am trying to make a query with a prepared statement to retrieve some information and make another query with the information 开发者_开发百科that was received from the first query, but i am receiving

I am trying to make a query with a prepared statement to retrieve some information and make another query with the information 开发者_开发百科that was received from the first query, but i am receiving the error:

Cannot pass parameter by reference

is there a way around this?

this is my code:

$DBH = getDBH();
$stmt = $DBH->prepare("SELECT small FROM info WHERE user = ?");
$stmt->bind_param("s",$userid);
$stmt->execute();
$stmt->bind_result($small);
$stmt->fetch();
$stmt->close();
$stmt = $DBH->prepare("INSERT INTO method(small) VALUES(?)");
$stmt->bind_param("s",$small);
$stmt->execute();
$stmt->close();


I think i may have got it to work by adding

return $small;

after

$stmt->fetch();

although i have not had time to test it with any actual values, I am not recieving any errors, but i am unsure if the code stops at

return $small;

or if everything continues to execute, i may be able to just rewrite it into a function and return the value.


Edit: Never mind the below! I was thinking of PDO


Try changing the following lines:

$stmt = $DBH->prepare("SELECT small FROM info WHERE user = :s");

and

$stmt = $DBH->prepare("INSERT INTO method(small) VALUES(:s)");

It's because you're trying to bind a nonexistent parameter. If you want to use question marks, you have to find it like so If I remember correctly.

$stmt->bind_param(0,$userid);
0

精彩评论

暂无评论...
验证码 换一张
取 消