Quick Answer
PDO connection: create a new PDO object with DSN string (mysql:host=localhost;dbname=mydb), username, and password. Set error mode to exceptions for proper error handling. Use prepare() to create a prepared statement, bind parameters, then execute(). PDO works with multiple databases. Store connection in a singleton or use a DI container to avoid opening multiple connections.
Answer
PDO connects PHP to MySQL using DSN strings and supports secure prepared statements.
S
SugharaIQ Editorial Team
Verified Answer
This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.
PHP interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Ideal for freshers and experienced candidates preparing for PHP roles.