abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

12/15/2020

What is PHP PDO, how it's work

 PDO refers to PHP Data Object, which is a PHP extension that defines a quick access database. 

Each database driver can expose database-specific features as a regular extension function that implements the PDO interface.

pdo connect to various database like sqlite, mysql, oracle


example of connect to database using PDO


<?php  

    $dbHost="localhost";  

    $dbName="myDB";  

    $dbUser="root"; 

    $dbPassword=""; 

    try{  

        $dbConn= new PDO("mysql:host=$dbHost;dbname=$dbName",$dbUser,$dbPassword);  

        Echo "Successfully connected with myDB database";  

    } catch(Exception $e){  

    Echo "Connection failed" . $e->getMessage();  

    }  

?> 


//above code short as $dbconn = new PDO("localhost","root","","myDB"); no need first five lines.


PDO is good as compare to mysqli , because, it connect with any database, mysqli only connect phpmyadmin mysql.


this PDO  connection short and quick connect. 


** PLEASE LIKE - SHARE - COMMENT **

No comments:

Post a Comment

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...