PHP bind_params with null

后端 未结 2 1018
不知归路
不知归路 2021-01-12 09:52

I am trying to bind params to a INSERT INTO MySQLi prepared statement if that variable exists, otherwise insert null.

This is what I have, but it is not working:

相关标签:
2条回答
  • 2021-01-12 10:44

    Keep in mind that you can't use bind_param twice, because the last statement will replace the first. Try to find a way to use bind_param just once.

    0 讨论(0)
  • 2021-01-12 10:53

    bind_param works by reference. That means that it takes a variable, then uses the value of that variable in execute.

    null is not a variable.

    Try setting a variable to null and then binding that variable instead.

    (Also consider using PDO instead of mysqli, where the execute method can take a simple array and you can bypass wacky binding methodology of mysqli.)

    0 讨论(0)
提交回复
热议问题