Question hub
Can PHP connect to a database?
The answer
Yes. PHP can connect to many databases, usually through the PDO extension or, for MySQL and MariaDB, the MySQLi extension. PDO gives one consistent interface for several database systems, while MySQLi is specific to MySQL. Whichever you use, send values with prepared statements so that visitor input is always treated as data. Keep the connection details outside your public web folder, and never place passwords in a file that can be downloaded.