
Dave Smith - 2015-11-24 00:28:54 -
In reply to message 1 from Colin McKinnon
I just checked out the site you provided a link to and the 'shim' they provide is similar to my PHP MySQL to MySQLi package that the article mentions near the end.
I did not look at their code, so I can't comment on it specifically, however they did mention that only a few of the common function replacements had been tested. Whether you use their package, or mine, doesn't matter much to me, both are released into the public domain as a service to hopefully curtail some of the blow back that will occur when shared hosts upgrade to PHP 7 and legacy code stops working.
I have been quite vocal, and I will state it again here, that these plug and play solutions are only a stop gap and should not be considered the cure. It is important that legacy code be update to a supported mysql extension, mySQLi or PDO, as soon as possible.
You are correct, my article is missing the mention of is_resource, so I can cover that quickly right here. With some additional considerations that dotpointer did not touch upon.
Since MySQL is a resource and MySQLi is an object, legacy code using the function is_resource to validate the connection must be changed when you migrate to MySQLi. Here are some points to consider when making this change.
1) is_resource is used for resources other than MySQL, so do not do a search and replace. You must ensure that the resource being evaluated is a MySQL resource, and then you can make the change.
2) Replace is_resource with is_object to evaluate whether the argument is an object, however make sure you also implement the next consideration.
3) mysqli_connect will return an empty object if the connection fails, so is_object will evaluate to true even if the connection failed. Right after you use MySQLi to establish a connection you MUST use mysqli_connect_error or mysqli_connect_errno to validate the connection, then there will be no surprises with the subsequent is_object checks.
Thanks for taking the time to comment,
Dave