Doubt about the error "Strict standards: Only variables should be passed by Reference in"

Asked

Viewed 3,453 times

3

To record some dates in the database in the desired format I am doing so:

 mysqli_stmt_bind_param
    (
        $stmt,
        's',
        date("Y-m-d", strtotime($data))
    );

Or, to catch the present day, simply:

 mysqli_stmt_bind_param
    (
        $stmt,
        's',
        date("Y-m-d")
    );

However, despite recording normally, I get this error (notice right?):

Strict standards: Only variables should be passed by Reference in line "5" // is on the date line...

Is this way of passing the value to the field wrong? What is the correct one? What does this error mean?

1 answer

3


Yes it’s wrong, mysqli_stmt_bind_param expects the second(oo) or third(procedural) argument to be at all times a reference that means it must be a variable and not the return of a function/method or value passed right.

The correct is to create a variable before calling mysqli_stmt_bind_param or do date search by database using function now() or equivalent.

$data = date("Y-m-d");
mysqli_stmt_bind_param($stmt, 's', $data);
  • Ah, got it, thanks!

  • @gustavox, this shouldn’t even work is all that’s in the line of error?

  • That’s all...

  • This question of mine is related, gives one in the comments of the answer accepted (whose solution I did not follow hehe)...

  • 1

    @gustavox, tested here worked (inserted) with a function return (which should not) already with a direct past value he did not Insert. I’ll see later because this behavior works, The idea is just to pass variables even :P.

  • hehe, I’ll fix here :-) thanks!

  • 1

    @Gustavox, there are some articles here on mysqi/Pdo and an improved class for making queries was that Soen user who did, it is worth taking a look.

Show 2 more comments

Browser other questions tagged

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