Mysqli Cannot pass Parameter 2 by Ference

Asked

Viewed 1,227 times

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;

The data type being (following the order): Int, Int, Varchar, Date.

But you are not registering.

  • There was no mistake?

  • Sorry Krismorte... we thought it was our mistake, but it’s not... we saw that there is no mistake... We checked if the nomenclature was right, number of fields, but nothing...

1 answer

3


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

The error generated is:

Fatal error: Cannot 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);
  • Bingo rray... that’s right... thank you so much for your help...

  • 1

    @Jose.Marcos this is one of the differences from Mysqli to PDO, in the second it is possible to pass direct values.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.