Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,889 members, 7,802,863 topics. Date: Friday, 19 April 2024 at 11:52 PM

PHP Mysql Connection Using PDO - Programming - Nairaland

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

Java JDBC Database Object Mysql Connection And Manipulation Library By Antware / Login And Regisatration In Php Using PDO / Learn PHP & MYSQL The Fast Way. (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.
SYNTAX:
$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.
<?php
$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();
}

?>

OUTPUT:
----------------------
Connected successfully

Learn more by following below link :
http://www.skptricks.com/2017/10/connections-and-connection-management-using-pdo-mysql.html

(1) (Reply)

Python And C++ Programmers Enter! / Html For Beginners 1 / MS SQL 17051 Startup Error

(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 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 6
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.