mysqli and object-oriented Approach

mysqli and object-oriented Approach

The mysqli extension allows you to access the functionality provided by MySQL 4.1 and above.
mysqli is designed with an object-oriented paradigm which allows the developers to work with an object-oriented interface. It is quite similar, although slightly more elegant (even for this old procedural-hacker) in that there is no need to pass the database handle for every function call, as the instantiated object takes care of that.

MySQL Improved Extension Allows two type of Approach
1. Procedural style and
2. Object oriented style

Procedural style :
—————–
Procedural style is the style we do with php4 and bellow.

<?php
$link = mysqli_connect(”localhost”, “my_user”, “my_password”);

$res = mysqli_query($link, “SELECT * FROM users”);

$value = mysqli_fetch_assoc($res);
?>

Object oriented style:
———————
Object oriented style will be like

<?php
$mysqli = new mysqli(”localhost”, “my_user”, “my_password”);

$result = $mysqli->query(”SELECT * FROM users”); /// Calling query using msqli object

$row = $result->fetch_assoc(); //// calling fetch_assoc using the result resource object

$mysqli->close();

?>

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.