If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

You got used to the autoglobal of the mysql resource (which was a really bad idea on zend's part). MySQLi doesn't exist outside of the scope it was created. You need to pass the resource to the functions in question.

PHP Code:

function db_query(MySQLi $mysqli, $query){ . . .}

If you have parametrized queries, you'll be wanting to use prepared statements instead. That I'd suggest writing a second function for, or modifying the first one to accept a third parameter array for the arguments, then determining if it should issue a ->query or ->prepare statement.

mysqli_init() is also not required. This is only required when you plan on modifying a few of the settings which must occur between the mysql_init and before the new mysqli() or mysqli_connect calls. There's not a whole lot of these configurations that require this though.

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

This isn't correct here: $getErrors = db_query(MySQLi $mysqli, "SELECT * FROM `errors` ORDER BY `id` DESC");. You cannot provide a datatype hint during the calling of the function; I mean the signature of the function can accept the typehint:

PHP Code:

function db_query(MySQLi $mysqli, $qry);

You are correct, the error for mysql_num_rows exists since you cannot combine mysqli and mysql libraries. I also don't recommend using the function calls since they differ between mysqli_stmt and mysqli_result objects. Instead, use them in object oriented fashion as they both share the same property name. Unfortunately, there is no superclass governing both mysqli_stmt and mysqli_result, so you cannot typehint:

That would work with both mysqli_result and mysqli_stmt objects. Of course a custom function is optional.

-> is object oriented de-reference operator. It resolves an object to a property or method of the class' instance. To use in context as I've indicated with the third parameter of the method, that would be like so:

Doesn't look right, but I can't test that where I am. The problem with the bind is that it expects to bind via reference, and dynamic counts in MySQLi are not accommodated so you need to invoke a callable/closure/reflection type in order for it to process. But something does look a little off.

If that works as I intend it to, than it would ultimately return a mysqli_result regardless of if it used a statement or not. I can't be 100% sure it would work; I've used pretty much prepared statements exclusively since the mysqli was released.

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)