There are at least three extension modules that provide access to a MySQL server: the old php-mysql module, the MySQL improved module and PDO with its MyQL driver. Pete has given you an example of the "old" mysql module. Let me show you an example using pdo and (server-side) prepared statements:
<?php
$pdo = new PDO('mysql:host=localhost;dbname=test', 'localonly', 'localonly');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
setupTestdata($pdo);
$stmt = $pdo->prepare('SELECT foo FROM soTest WHERE id<?');
$stmt->execute( array(3) );
while( false!==($row=$stmt->fetch(PDO::FETCH_ASSOC)) ) {
echo $row['foo'], "\n";
}
echo "same statement again, different parameter:\n";
$stmt->execute( array(5) );
while( false!==($row=$stmt->fetch(PDO::FETCH_ASSOC)) ) {
echo $row['foo'], "\n";
}
function setupTestdata($pdo) {
$pdo->query('CREATE TEMPORARY TABLE soTest (id int auto_increment, foo varchar(16), primary key(id))');
$pdo->query("INSERT INTO soTest (foo) VALUES ('nameA'), ('nameB'), ('nameC'), ('nameD'), ('nameE')");
}
prints
nameA
nameB
same statement again, different parameter:
nameA
nameB
nameC
nameD