Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

mysqli - PHP error: "Cannot pass parameter 2 by reference"

I just need help on this PHP error which I do not quite understand:

Fatal error: Cannot pass parameter 2 by reference in /web/stud/openup/inactivatesession.php on line 13

<?php

error_reporting(E_ALL);

include('connect.php');

$createDate = mktime(0,0,0,09,05,date("Y"));
$selectedDate =  date('d-m-Y', ($createDate));

$sql = "UPDATE Session SET Active = ? WHERE DATE_FORMAT(SessionDate,'%Y-%m-%d' ) <= ?";                                         
$update = $mysqli->prepare($sql);
$update->bind_param("is", 0, $selectedDate);  //LINE 13
$update->execute();

?>

What does this error mean? How can this error be fixed?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The error means that the 2nd argument is expected to be a reference to a variable.

Since you are not handing a variable but an integer of value 0, it generates said error.

To circumvent this do:

$a = 0;
$update->bind_param("is", $a, $selectedDate);  //LINE 13

In case you want to understand what is happening, as opposed to just fixing your Fatal error, read this: http://php.net/manual/en/language.references.pass.php


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...