PHP and MySQL Flashcards
Q: What is MySQL?
A: A relational database management system (RDBMS) that stores and manages data.
Q: How does PHP interact with MySQL?
A: PHP uses extensions like mysqli or PDO to interact with MySQL databases.
Q: What is the difference between mysqli and PDO?
A: mysqli is specific to MySQL, while PDO supports multiple databases.
Q: What is the default MySQL port?
A: Port 3306.
Q: What PHP function is used to connect to a MySQL database using mysqli?
A: mysqli_connect().
Q: How do you create a MySQL database connection with mysqli?
$conn = mysqli_connect(“host”, “username”, “password”, “database”);
Q: What function checks if a database connection was successful?
A: mysqli_connect_errno().
Q: How do you close a MySQL connection in PHP?
A: Use mysqli_close($conn);.
Q: What exception is thrown for connection errors in PDO?
A: PDOException.
Q: How do you set up a database connection using PDO?
$pdo = new PDO(“mysql:host=host;dbname=database”, “username”, “password”);
Q: What function is used to execute a query in mysqli?
A: mysqli_query().
Q: How do you execute a query using PDO?
A: Use the query() or prepare() method.
Q: What function fetches data as an associative array in mysqli?
A: mysqli_fetch_assoc().
Q: What method fetches data in PDO?
A: Use fetch() or fetchAll().
Q: How do you handle errors during a query in mysqli?
A: Check mysqli_error($conn).
Q: What are prepared statements in PHP?
A: A way to execute SQL queries with placeholders to prevent SQL injection.