0

I am in the process of converting an old PHP script to make it PHP 7.x compatible so I have to change all the mysql_query() to mysqli_query().

Question: is it the same to have mysqli_query($query, $connection) vs mysqli_query($connection, $query)?

I am noticing that in this script sometimes the query is first and then the connection but on the PHP manual it indicates the connection should be before the query:

mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] ) : mixed

Does it matter? Or do I need to change it all the mysql_query($query, $connection) to mysqli_query($connection, $query)?

Thank you

Dharman
  • 30,962
  • 25
  • 85
  • 135
marcnyc
  • 585
  • 1
  • 4
  • 17
  • 2
    The manual is correct. The connection must come before the query. But if you are touching the code anyway using PDO would be a better choice IMO. – Dave May 07 '20 at 19:21
  • 2
    @Dave for such a mechanical replacement without prepared statements it doesn't really matter – Your Common Sense May 07 '20 at 19:29
  • thank you guys... too bad the PHP folks didn't stick to the previous way, would have been it much easier to just add an "i" – marcnyc May 07 '20 at 19:46
  • 1
    If you are just adding an i then you are doing it wrong already. The whole reason why that old API was removed is to force people to use parameterized prepared statements. For this you need to do much more changes and PDO is a better option. See my article here https://github.com/kamil-tekiela/mysql-to-mysqli – Dharman May 07 '20 at 23:05

0 Answers0