pa-p
12/23/2017 - 4:13 PM

MySQL Notes

Create DB Conneciton

<?php

error_reporting(1);
$host="localhost";
$user="root";
$pass="";
//connection
$con=mysql_connect($host,$user,$pass) or die(mysql_error());
//db selection
mysql_select_db("ajax-tutorial1",$con);

?>

<!--===========================-->
<!-- ======== With PDO ========-->
<!--===========================-->

<?php

error_reporting(1);
$dbhost="localhost";
$dbname='chat_system';
$dbuser="root";
$dbpass="";

// DB Connection with PDO Method
try {
    $db = new PDO("mysql:dbhost=$dbhost;dbname=$dbname", "$dbuser", "$dbpass");
} catch( PDOException $e ) {
    echo $e->getMessage();
}

?>