Nearly every site that you visit nowadays has some sort of database storage in place, many sites opt to use MySQL databases when using PHP. However, many people haven’t yet taken the step to interacting with databases properly in PHP. Here we guide you through what you should be doing – using PHP’s MySQLi class – with a hat-tip to the one way that you definitely shouldn’t be doing it.
$db variable require which we used in DB connection. e.g.
DB Connection:
1 2 3 4 5 6 7 8 | <?php $db = new mysqli('localhost', 'root', '', 'popink'); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } ?> |
Unlink/Delete uploaded file from folder:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php $result = mysqli_query($db,"SELECT * FROM home_slider WHERE id='$id'"); $row = mysqli_fetch_array($result); $old_file2="../images/slider/$row[banner]"; $del2= unlink($old_file2); ?> |
Delete Query:
1 | $delete=$db->query("DELETE FROM home_slider WHERE id='$id'") ; |
Source: http://codular.com/php-mysqli