mysql_query() executed SQL through PHP's original MySQL extension. The extension was removed in PHP 7. Current code should use PDO or MySQLi, and variable data should be passed through prepared statements.
<?php
// Historical only: removed from PHP 7+
$query = 'SELECT name, class, mark FROM student';
$status = mysql_query($query);
?>
<?php
$stmt = $dbo->query(
'SELECT name, class, mark FROM student ORDER BY id'
);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
query() is appropriate for SQL that contains no untrusted values.
<?php
$stmt = $dbo->prepare(
'SELECT name, class, mark FROM student WHERE class = :class'
);
$stmt->execute(['class' => 'Four']);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<?php
$stmt = $connection->prepare(
'SELECT name, class, mark FROM student WHERE class = ?'
);
$class = 'Four';
$stmt->bind_param('s', $class);
$stmt->execute();
$result = $stmt->get_result();
?>
<?php
$stmt = $dbo->prepare(
'UPDATE student SET mark = :mark WHERE id = :id'
);
$stmt->execute(['mark' => 80, 'id' => 1]);
echo $stmt->rowCount();
?>
For failures, prefer exceptions or inspect the current driver's error information rather than terminating with a raw database error. See MySQL error handling and affected rows.
The sample student dataset remains available from student table SQL. For query fundamentals, continue with SELECT, WHERE, and UPDATE.
PHP-specific companions: MySQLi overview and MySQLi query examples.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.