ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.28k stars 1.35k forks source link

how show a sql query ? #1004

Closed khanhnam99 closed 8 months ago

khanhnam99 commented 1 year ago

how show a sql query ?

s-vhs commented 1 year ago

By using the getLastQuery() function.

$conn = new MysqliDb("localhost", "root", "root", "testDb"); // create new connection
$username = $conn->escape($_GET["username"]); // get username to get users by
$result = $conn->orderBy("id", "DESC")->where("username", "%" . $username . "%", "like")->get("users"); // get users from db
//print_r($result); // gives out our result
echo $conn->getLastQuery(); // gets last executed query in SQL format

This should be the proper way to use it. As an example, I selected a few users with a LIKE and ORDER BY condition. You can use whatever query and variable for the connection you want, just use, after execution of the query, the getLastQuery() function.

I hope I was of help :)

khanhnam99 commented 1 year ago

Great! thanks