Connecting to your MySQL Database from a Php page using PDO (PHP Data Objects)
In order to connect to a MySQL DB from Php, you need to frame the connection string and Index.php <?php include_once("config.php"); ?> Config.php <?php //set off all error for security purposes error_reporting(E_ALL); //define some contstant define( "DB_DSN", "mysql:host=localhost;dbname=<myDBName>" ); define( "DB_USERNAME", "root" ); define( "DB_PASSWORD", "<myrootpasswordhere>" ); define( "CLS_PATH", "class" ); //include the classes include_once( CLS_PATH . "/DBClass.php" ); ?> DBClass.php <?php class DBClass { public function Connect_mysqlDB(){ try { $con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); $con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION […]
Read more