Saturday, October 27, 2018

MySql vs MySqli

Basically, MySQL is the old database driver, and MySQLi is the Improved driver. The "i" stands for "improved" so it is MySQL improved.
MySQLi can be done procedural and object-oriented whereas MySQL can only be used procedurally. Mysqli also supports prepared statements which protect from SQL Injection.

MySQL extension added in PHP version 2.0. and deprecated as of PHP 5.5.0.

MySQLi extension added in PHP 5.5 and will work on MySQL 4.1.3 or above.

Connect with MySqli :-

<?php
define('DB_SERVER','localhost');
define('DB_USER','database_user_name');
define('DB_PASS' ,'db_password');
define('DB_NAME', 'db_name');
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
if (mysqli_connect_errno())
{
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>

Connect with MySql :-


 <?php
         $dbhost = 'localhost';
         $dbuser = 'db_username';
         $dbpass = 'db_password';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully';
         mysql_close($conn);
      ?>

For any quary, suggesion, advice about this topic kindly Comment below.


Related Posts:

  • How to delete data from database using MVC? Delete data from database using MVC You can easily delete the records from database. In this below example we have used three php files 1. View.php <?php include("controller.php"); //delete the data  if(isset($_R… Read More
  • How to update multiple table in MySQL? Update multiple table with join in MYSQL <?php      $sql = "UPDATE table1                  JOIN table2 VCR ON  (table1.contact_id = table2.contact_id) &n… Read More
  • What is session in php? how can use the php session? What is Session:- A php Session variable  is stored the single user information and are available all the page in the application.A PHP session solves this problem by allowing you to store single user … Read More
  • Image upload by ajax in php AJAX Image upload in php It's very simple process to image upload by AJAX . It's working fine. You can easily upload the image by AJAX. Follow the below step. Code download  Click Here 1. Create a simple .php or .htm… Read More
  • How can edit the data in MySql using core php ? form.php <?php mysql_connect("localhost","root",""); mysql_select_db("project"); //edit if (isset($_REQUEST['edit_id'])) { $eid=$_REQUEST['edit_id']; $select="select * from tbl_user where id='$eid' ";… Read More

1 comment: