I'm still new to PHP and MYSQL and I'm trying to learn both with modern coding techniques. All the stuff I find online seems to be outdated.
Can anybody suggest anything for me? I am also curious if the below code is outdated? If it is indeed outdated, can you suggest newer and safer methods?
<?php
$connection = mysql_connect("localhost", "root", "");
if (!$connection) {
die("Oops, error happened: " . mysql_error());
}
?>
There are two popular ways to connect to a MySQL database using PHP: With PHP's MySQLi Extension. With PHP Data Objects (PDO)
Use PDO
functions.
Database Connection Using PDO:
$conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With