Hi friends how are you and today I discuss about MySQL and mysqli so let’s Begin start now .
1. MySQL does not need GUI tools in order to administer databases or manage the data therein;
2.MySQL is an RDBMS that runs as a server and provides multi-user access to multiple databases.
3. MySQL can only be used procedurally
4. As PHP 7 & > has removed the support of mysql
Mysql support only Procedural which example given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) die("Connection failed: " . $conn->connect_error); $result = $conn->query("SELECT id, firstname, lastname FROM Employee"); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; } } else echo "0 results"; $conn->close(); |
MySQLi Extension (or simply known as MySQL Improved or MySQLi) is a relational database driver that is used mainly in the PHP programming language.
Mysqli provides an interface to the already founded MySQL databases.
Mysqli is quite literally an improved version of its predecessor, MySQL, which was simply a means to manage databases over servers.
Mysqli support for previously prepared statements which protect from SQL Injection , and enhanced embedded server support.
Mysqli support multiple statements.
MySQLi can be done procedural and object-oriented
Mysql support for transactions
Note: As PHP 7 & > has removed the support of mysql, now I am forced to use mysqli instead, but this will consume too much time for me
Mysqli support both Procedural and Object-oriented which example given below.
Ex1: Procedural process
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$conn = mysqli_connect($servername, $username, $password, $dbname); if (!$conn) die("Connection failed: " . mysqli_connect_error()); $result = mysqli_query($conn, "SELECT id, firstname, lastname FROM Employee"); if (mysqli_num_rows($result) > 0) while($row = mysqli_fetch_assoc($result)) echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. " else echo "0 results"; mysqli_close($conn); |
Ex1: Object-oriented process
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) die("Connection failed: " . $conn->connect_error); $result = $conn->query("SELECT id, firstname, lastname FROM MyGuests"); if ($result->num_rows > 0) { echo "<table><tr><th>ID</th><th>Name</th></tr>"; // output data of each row while($row = $result->fetch_assoc()) { echo "<tr><td>".$row["id"]."</td><td>".$row["firstname"]." ".$row["lastname"]."</td></tr>"; } echo "</table>"; } else echo "0 results"; $conn->close(); |
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.
The main useful features are:
- an Object-oriented interface
- support for prepared statements
- support for multiple statements
- support for transactions
- enhanced debugging capabilities
- embedded server support.
NOTE: MySQL was deprecated in PHP 5.5.0 and was removed in PHP 7.