$mysqli = new mysqli("localhost", "username", "password", "database"); $id = 1; $result = $mysqli->query("SELECT * FROM employees WHERE id = $id"); $row = $result->fetch_assoc();
$mysqli = new mysqli("localhost", "username", "password", "database"); $result = $mysqli->query("SELECT COUNT(*) FROM products"); $count = $result->fetch_row()[0];This code uses the mysqli constructor to set up a connection to the database. The query function is then used to execute the SQL query, which selects the count of all rows from the products table. The fetch_row function is used to retrieve the first row of the result set as a numeric array, and the [0] index is used to retrieve the first element of that array, which is the count of rows. The PHP MySQL extension is built-in and does not require any additional package libraries.