Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE new_messages ( id INT AUTO_INCREMENT, message VARCHAR(100), username VARCHAR(100), PRIMARY KEY (id) ); INSERT INTO new_messages (message, username) VALUES ('hi', 'Amad'), ('sup', 'Bashir'), ('stuff', 'Amad'), ('really', 'Bashir'), ('not really', 'Amad'), ('cool', 'Bashir'), ('see ya', 'Amad'), ('out', 'Bashir');

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php // $mysqli is already declared as a working database connection by this sandbox $session = (object) [ 'username' => 'Bashir' ]; $sql = <<<SQL SELECT * FROM new_messages WHERE username=? SQL; var_export( (fn($obj) => [ 'total' => $obj->num_rows, 'data' => $obj->fetch_all(MYSQLI_ASSOC) ])($mysqli->execute_query($sql, [$session->username])) );
Copy Clear