PHP Data Objects - PDO


PHP PDO & MYsQL PDO provides an abstract layer to access different databases ( including MySQL ). PDO support is available for 12 different databases.

The advantage of using PDO is portability across different database without changing functions. Only the connection string needs to be changed.
PHP Data Object PDO installation or enable and creating connection string to manage MySQL database

PHP driver MySQLi is exclusively for MySQL database, whereas PDO is an interface for accessing different databases ( including MySQL ) from PHP .

How to check the supported databases?
var_dump(PDO::getAvailableDrivers());
Output ( this will change based on your PHP installation / support )
array(2) { [0]=> string(5) "mysql" [1]=> string(6) "sqlite" }
Follow the instructions at php.ini here to enable the support. PDO will not work for versions older than PHP 5 ( Check your PHP Version )

Read the tutorials on pdo_sqlite to manage SQLite database using PDO SQLite drivers. Download Zip file with all sample scripts at end of this page

MySQL Functions (PDO_MYSQL)

Basics
Functions Description
InstallationHow to enable PDO in PHP 5 and above versions
ConnectionConnection to MySQL Database

CRUD : Create Read Update Delete

Functions Description
FetchCollecting single record
RecordsMultiple records from table

Inserting , updating and deleting records
Functions Description
InsertAdding records to table
UpdateUpdate record
DeleteDelete records
DropDrop table

Counting rows and columns
Functions Description
RowCountNumber of rows affected by delete or update query
ColumnCountNumber of columns present in a query or table
Blob
Functions Description
BlobManaging Binary data using Blob data type
UploadUpload photo to add to Blob column of MySQL database

From a list of records to a single record

We can display a list of student names by taking data from a table. From this list user can click a single record ( say student name column ) to get full details of the record ( student details )
Basic Php MySQL database script using PDO
You should have PHP installed
Database MySQL
Check PDO connection from PHP to MySQL

How to Install Script
Open sql_dump.txt file and use the sql commands to create your tables.
Open config.php and enter your mysql login details.

Open index.php file and check for any error messages
Open any file and use the top menu to navigate different pages
You can delete table or remove all records by using different pages using top menu.
You can re-initiate all tables and records by visiting links at the top menu.
So feel free to experiment with drop table or deleting records.

PHP MySQL PDO sample script installation using MySQL dump and crating tables in Workbench




download Basic database management script using PHP PDO & MySQL ( pdo-basic.zip )

MYSQLI Functions PHP Code generator for PDO & mysqli
Title Thumbnail
#1PHP Data Object PDO installation or enable and creating connection string to manage MySQL database
https://youtu.be/Do7jgpqzgBU
#2PHP MySQL PDO sample script installation using MySQL dump and crating tables in Workbench
https://youtu.be/fdLanaYNduI
#3Displaying records from sample tables using SELECT query in PHP MySQL using PDO functions
https://youtu.be/8_ib5zBDCOg
#4Parameterized query in PHP PDO using bindParam() in sending data separately to MySQL database
https://youtu.be/U-5Giq-KqJk
#5PHP PDO Parameterized query to insert data to MySQL table and getting lastInsertId() of the record
https://youtu.be/0JRz1Ft7HQA
#6PHP PDO update query using parameters with user inputs and counting number rows updated.
https://youtu.be/o5I3sRQcWxY
#7rowcount() to get number of records affected by Query involving any Delete , update & insert command
https://youtu.be/YtcjstVFguo
Hindi
Title Thumbnail
#1PHP Data Object PDO installation or enable with connection string to MySQL database in HINDI
https://youtu.be/G2x88G7rI4g
#2PHP MySQL PDO sample script installation using MySQL dump and crating tables in Workbench in HIND
https://youtu.be/jDycwDsixq8
#3Displaying records from sample tables using SELECT query in PHP MySQL using PDO functions in HINDI
https://youtu.be/7eQ9mwIbNIs
#4Parameterized query in PHP PDO using bindParam() in sending data separately to MySQL table in HINDI
https://youtu.be/LavT4d_7IKo
#5PHP PDO Parameterized query to insert data to MySQL table and lastInsertId() of the record in HINDI
https://youtu.be/_NknWf601XA


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer