jan jan - 5 years ago 107
PHP Question

what's the mysqli prepared statement equivalent to this?

I have this code

$query = mysql_query("SELECT * FROM users ORDER BY exp DESC LIMIT ".$lim.", 10");


while($row = mysql_fetch_array($query))

but what's the mysqli equivalent to this (featuring prepared statements). I can't get along.

Answer Source

Prepared statement placeholders can only be used in places where the SQL allows an expression, but LIMIT requires its parameter to be a literal. Since you can't use a placeholder there, the mysqli equivalent is basically the same as the mysql version, there's no benefit from using a prepared statement. The only difference is that mysqli_query requires the connection object as its first argument.

$query = mysqli_query($conn, "SELECT * FROM users ORDER BY exp DESC LIMIT ".$lim.", 10");
while($row = mysqli_fetch_array($query)) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download