Jump to: navigation, search

PHP MySQL PDO Connect

From w3cyberlearnings

Contents

PHP PDO Connection

PDO Connection to connect to the MySQL server.

Syntax PDO connection


$dns ='mysql:host=localhost;dbname=w3cyberlearning';
$user = 'user2000';
$pass = 'password2000';
$db = new PDO($dns,$user, $pass);

Example 1: Use try and catch block

<?php

try {
	$db = new PDO('mysql:host=localhost;dbname=w3cyberlearning', 
			  'user2000', 
			  'password2000');
	echo 'connect';
} catch (PDOException $e) {
	echo $e->getMessage();
}

?>


Related Links


Navigation
Web
SQL
MISC
References