1. What does PDO stand for in PHP?
PDO stands for PHP Data Object. It provides a database abstraction layer that works with many database systems like MySQL, SQLite, and PostgreSQL.
$pdo = new PDO('mysql:host=localhost;dbname=test','root','pass');Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
PHP · Question Set
Database Integration interview questions for placements and exams.
Questions
15
Included in this set
Subject
PHP
Explore more sets
Difficulty
Mixed
Level of this set
Go through each question and its explanation. Use this set as a focused practice pack for PHP.
PDO stands for PHP Data Object. It provides a database abstraction layer that works with many database systems like MySQL, SQLite, and PostgreSQL.
$pdo = new PDO('mysql:host=localhost;dbname=test','root','pass');For complete preparation, combine this set with full subject-wise practice for PHP. You can also explore other subjects and sets from the links below.
CRUD stands for Create, Read, Update, and Delete. Create inserts new records, Read retrieves them, Update modifies existing ones, and Delete removes them. All four are performed using SQL queries with secure data handling practices.
If mysqli_connect fails, it returns false. You can check this and display an error using mysqli_connect_error.
if(!$conn){ echo mysqli_connect_error(); }The bind_param function binds PHP variables to the SQL query placeholders before execution. It helps ensure secure and structured queries.
$stmt->bind_param('s',$name);The fetch method of PDOStatement retrieves the next row from the result set. It can return associative or numeric arrays depending on fetch mode.
$row = $stmt->fetch(PDO::FETCH_ASSOC);
SQL injection occurs when untrusted input is directly used in SQL queries, allowing attackers to manipulate database commands. It can be prevented using prepared statements, parameter binding, and input validation before executing queries.
MySQLi works only with MySQL, while PDO supports multiple databases like SQLite and PostgreSQL. PDO provides a consistent API and supports named parameters, while MySQLi offers both object-oriented and procedural styles.
You can check connection results and display user-friendly messages instead of system errors. For PDO, you can enable exceptions using error mode attributes to handle errors cleanly without exposing sensitive information.
A transaction is a sequence of SQL operations that execute as a single unit. It ensures data integrity. You can start a transaction, execute multiple queries, and either commit or roll back if something fails.
$pdo->beginTransaction(); $pdo->commit();
PDO can throw exceptions on errors when error mode is set to ERRMODE_EXCEPTION. This allows structured error handling through try-catch blocks instead of checking return values manually.
Use environment variables for credentials, close unused connections, use persistent connections only when needed, and always use prepared statements. Avoid hardcoding passwords or connection details directly in scripts.
MySQLi stands for MySQL Improved. It allows PHP scripts to connect and interact with MySQL databases securely and efficiently.
$conn = mysqli_connect('localhost','root','pass','test');The mysqli_query function sends a query to the MySQL server and returns a result object for SELECT or true for successful INSERT, UPDATE, or DELETE operations.
$result = mysqli_query($conn,'SELECT * FROM users');
mysqli_fetch_assoc fetches one row from the result set and returns it as an associative array where column names are used as keys.
$row = mysqli_fetch_assoc($result);
Prepared statements increase performance by precompiling SQL and prevent SQL injection by separating query structure from user data.
$stmt = $pdo->prepare('SELECT * FROM users WHERE id=?');