Do not use the old mysql api
There are several ways to connect to a MySQL database in PHP. The most common ones are the MySQL API, the MySQLi API and the PDO API (PHP Data Objects). The last two support more features than the old mysql API and are more secure. If you’re using the old “mysql_” functions, you should stop and learn the new PDO API. Those old mysql functions are deprecated and are no longer supported in PHP 7.x.
Bad practice:
<?php $con = mysql_connect("localhost", "root", "mypass") or die("Could not connect: " . mysql_error()); mysql_select_db("tutorials"); $result = mysql_query("select * from tutorials"); echo "<h2>Here is a list of the topics:</h2>"; while ($row = mysql_fetch_array($result)) { echo $row['name']."<br />"; } mysql_close($con); ?>
Better practice:
…[Read more]