MySQL PDO Tutorial - Introduction

preview_player
Показать описание

This is a short series of tutorials on how to connect to a MySQL database using a PDO connection and display the database records in the browser.

Why should we use PDO?

Well first there is a choice of only two ways to connect – either mysqli, the ‘i’ standing for ‘improved’, or PDO, which stands for ‘PHP data objects’.

The old mysql_* commands are deprecated and inherently a security risk and should no longer be used. If possible they should be replaced in old code.

Both PDO and mysqli are equivalent in terms of security as both support prepared statements, meaning that user input is not entered straight into the SQL query but sent along a different channel where it is sanitised and safe to use. So both remove the risk of SQL injection inherent in using mysql_* commands.

Unlike mysqli, PDO supports named parameters and placeholder question marks; mysqli only supports placeholders. I will show how to work with both in this tutorial and you will see that named parameters are an easier and more convenient way of working with database fields easier.

Unlike mysqli, PDO supports many different database vendors – mysqli as we would gather from the name, only supports mysql databases. If you did have to swap from one database type to another you would still have work to do as the SQL queries would be different, but at least it would be possible without many changes.

In summary, PDO is secure, flexible, and convenient and the best choice for all new projects and updates.

Once you've done that, let's get started...
Рекомендации по теме
Комментарии
Автор

The introduction is very clear. It is explained clearly. Thank you very much.

srinivasaraoyp
Автор

I kept facing problems with php codes using MySQL database.. and I am getting tired of it. So, right now I am ready for your amazing tutorials Mr. Stibbard, O thank you very much sir!

xmx
Автор

Hello Dr. Stibbard ! Thank you so much for these tutorial lession, awesome how easy you explained us what we need to know.

kaydues
Автор

You are awesome. Thanks for that perfect easy to understand and learning tutorial. God Bless You

zdravkokrastev
Автор

incredibly useful.
I sincerely thank you!

coldmow
Автор

Thanks for these videos. I hope you will carry on

santoshdevnath
Автор

With the connection file, would there be any issue with writing your connection like

$user = 'root';
$password = 'password';
$host = 'localhost';
$db = 'cms';

try{

$pdo = new PDO('mysql:host=' . $host . ';dbname=' . $db . ';charset=utf8', $user, $password);
//var_dump($pdo);
} catch(Exception $e) {
echo 'There is a problem connecting you to the database, please try again later.';
//echo $e->getMessage();
}

I am thinking the variables kept in another file convar.php and included in the connection file but then you can just amend as required if live or local site?

Thanks

DavidAshby
Автор

can you make a video of how to store files in filesystem and storing their url in the database.
would really appreciate.

nickbizz
Автор

please the link is not opening. its sending a msg that the page isnt found

johnsonanuoluwapo
join shbcf.ru