Skip to content
PHP Logo

What alternative functions should be used instead of mysql_db_query in PHP?

The mysql_db_query function in PHP is deprecated and should not be used in new code. Instead, developers should use the mysqli or PDO extensions to interact with MySQL databases. These extensions provide more secure and efficient ways to execute queries and handle database connections in PHP.

php
// Using mysqli extension
$mysqli = new mysqli("localhost", "username", "password", "database");
$result = $mysqli->query("SELECT * FROM table");

// Using PDO extension
$pdo = new PDO("mysql:host=localhost;dbname=database", "username", "password");
$stmt = $pdo->query("SELECT * FROM table");