Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,921 members, 7,956,463 topics. Date: Monday, 23 September 2024 at 12:27 PM |
Nairaland Forum / Science/Technology / Programming / PHP Mysql Connection Using PDO (894 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" $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)
Anyone Base In Ikotun-egbe Area Who Knw A Better Centre To Learn Graphic Design / Facebook And Instagram Ad Issues / 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. 8 |