Welcome, Guest: Join Nairaland / LOGIN! / Trending / Recent / New
Stats: 2,863,594 members, 6,870,739 topics. Date: Thursday, 19 May 2022 at 03:33 PM

PHP Mysql Connection Using PDO - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / PHP Mysql Connection Using PDO (788 Views)

Java JDBC Database Object Mysql Connection And Manipulation Library By Antware / PDO::FETCH_CLASS Example / Login And Regisatration In Php Using PDO (2) (3) (4)

(1) (Reply)

PHP Mysql Connection Using PDO by skptricks: 2:05pm On Oct 19, 2017
Today, In this post we will learn how to connect to MySQL using PDO in PHP and just for the information PDO stands for "PHP Data Objects".
Here we will see the some useful examples to perform CURD operations in MySQL database using PDO and also it provides you some information about MySQL Prepared Statement.

Connections to MySQL database can be established by creating instances of the PDO base class and specify the driver, database name, username, and password.
$dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);

Connection to MySQL Databse Using PDO

Lets see the simple example to establish the database connection to MySQL using PDO.
$dbhost ="localhost"; // set the hostname
$dbname ="skptricksdemo" ; // set the database name
$dbuser ="root" ; // set the mysql username
$dbpass =""; // set the mysql password

try {
$dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbConnection->exec("set names utf8"wink;
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();


Connected successfully

Learn more by following below link :

(1) (Reply)

Software Testers Interview Questions With Answers-part1 / 10 Questions You Need To Ask Before You Hire Magento Developers / Programming Training Institute (advise)

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2022 Oluwaseun Osewa. All rights reserved. See How To Advertise. 29
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.