MySQLi Can not pass parameter 2 by reference

1

Colleagues.

I have the following code below:

$conexao = new mysqli('127.0.0.1','root','','teste');
if(mysqli_connect_errno()) die(trigger_error(mysqli_connect_errno()));

$cadastrar  = $conexao->prepare("INSERT INTO cad_produtos VALUES(?,?,?,?)");     
        $cadastrar->bind_param('iiss',
                                null,
                                '111',
                                '11',
                                '2016-03-01');
$cadastrar->execute();
$idCod = $cadastrar->insert_id;

Given that the data type is (following the order): Int, Int, Varchar, Date.

But you are not registering.

    
asked by anonymous 01.03.2016 / 17:35

1 answer

2

bind_param() does not accept values as second argument, only references or are variables, assign the values in it and problem solved.

The error generated is:

  

Fatal error: Can not pass parameter 2 by reference in

Change:

$cadastrar->bind_param('iiss', null, '111', '11', '2016-03-01');

To:

$id = null;
$var = 111;
var2= 11;
$data= '2016-03-01';
$cadastrar->bind_param('iiss', $id, $var, $va2, $data);
    
01.03.2016 / 18:03