// create a new PDO connection object $pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password'); // prepare the SQL statement $stmt = $pdo->prepare('SELECT * FROM users WHERE age > :age'); // bind the parameter $stmt->bindParam(':age', $age, PDO::PARAM_INT); // execute the query $stmt->execute(); // fetch the results $results = $stmt->fetchAll(PDO::FETCH_ASSOC); // print the results print_r($results);
// create a new MySQLi connection object $mysqli = new mysqli('localhost', 'username', 'password', 'mydatabase'); // prepare the SQL statement $stmt = $mysqli->prepare('SELECT * FROM users WHERE age > ?'); // bind the parameter $stmt->bind_param('i', $age); // execute the query $stmt->execute(); // fetch the results $results = $stmt->get_result()->fetch_all(MYSQLI_ASSOC); // print the results print_r($results);In this example, we are using the MySQLi extension to connect to a MySQL database and select all records from the "users" table where the age is greater than a specified value. We are also using parameter binding to prevent SQL injection attacks. The selectSql function is a part of various packages and libraries, including PDO and MySQLi.