0) { // Output data of each row while($row = mysqli_fetch_assoc($result)) { echo "Name: " . $row["name"]. " Age: " . $row["age"]. "
"; } } else { echo "0 results"; } // Close database connection mysqli_close($conn); ?>
This example connects to a PostgreSQL database, prepares a SQL query with placeholders, prepares a statement object, and executes the query with the user inputs using prepared statements to prevent SQL injection attacks. Package/library: PostgreSQL In conclusion, the executeQuery method is a powerful tool for interacting with databases using PHP. The examples provided demonstrate its use with MySQL and PostgreSQL databases, and the library/package used for each example are MySQLi and PostgreSQL respectively.