PDO Database Connection in PHP
How to connect to database in php using pdo?
Explanation
Every database have a slightly different connection method from the other. Listed below are the method to connect to the most popular databases.
To create database connections using PDO extension, you should pass four types of variable. They are,
- Database Name
- Host Name
- Valid login name
- Correct password to login
Database Handle = new PDO("Databse type:host=hostname;dbname=dbname;",username,password)
Example :
$host = localhost;
$dbname = pdo_db;
$username = uername;
$password = pasword;
$db = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
After connecting with the database using PDO, we can create table and perform query functions like insert, update, select and delete.