Example of PDO - CodeTextPro | Free Web Tutorial

Codetextpro Provides free Web tutorial, HTML, CSS, C, C++, Java, JavaScript, PHP, MySql, Python, Program, Programming Notes, Programming Questions and more.

Programming

Monday, December 10, 2018

Example of PDO

Example (PDO) (PHP Data Objects): 


<?php 
$servername = "localhost";
$username = "username";
$password = "password";
try {   
$conn = new PDO("mysql:host=$servername",
$username, $password);   
 // set the PDO error mode to exception   
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);   
$sql = "CREATE DATABASE myDBPDO";   
// use exec() because no results are returned   
$conn->exec($sql);   
echo "Database created successfully<br>"; 
 }
catch(PDOException $e)   
{   
echo $sql . "<br>" . $e->getMessage();
 }
$conn = null;
?> 

No comments:

Post a Comment