TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-22-2007, 03:03 PM   #1 (permalink)
The Contributor
Upcoming Programmer 
 
Matt83's Avatar
 
Join Date: Oct 2007
Location: Argentina
Posts: 72
Thanks: 18
Matt83 is on a distinguished road
Plugin/Addon mysqli OOP interface introduction

When PHP 5 and MySQL 4.1 came by, there where so many new points to include or change in the old ext/mysql that they came to the conclusion that it was better to release a new extension, basically as a way to start over and clean things up. mysqli is the "new" extension provided in PHP5 that its designed to work and support the new features found in Mysql version 4.1.3 or above. It includes SSL connections, stronger password algorithm, prevents SQL injection, makes use of new and more efficient MySQL binary protocol and more. Overall it provides greater speed, better security and new/improved features. One of them that i like its the object-oriented interface. It said that the OOP interface is slightly slower than the procedural interface but its tiny compared for the time it saves when writing code and how much easier to read it makes it.

Mysqli OOP interface sample:

PHP Code:
<?php
# ------------------------------------------------------------
# Simple script to fetch an associative array.
# ------------------------------------------------------------

// Connect To Database
$dbh = new mysqli"host","user","pass","database" ) or die( mysqli_error$dbh ) );

// Query
$res $dbh->query('SELECT * FROM table');

while ( 
$row $res->fetch_assoc() )

      
/* */
}
?>
The example above can of course be achieved with regular mysql functions ( as you may see the code above is pretty similar to the old ext/mysql ) but the mysqli OOP interface is much more cleaner from a visually point of view.

Here you can see a list of methods and properties that can be used with mysqli: PHP: mysqli - Manual

There are a good bunch of other things to mention about mysqli like multiple queries, prepared statements, the support for commit and rollback, etc. Anyways i hope this brought some light on this subject as i believe everyone should be encouraged to start using this extension.

Cheers
__________________
http://www.mattvarone.com

Last edited by Matt83 : 12-22-2007 at 03:54 PM.
Matt83 is offline  
Reply With Quote
The Following User Says Thank You to Matt83 For This Useful Post:
Orc (12-22-2007)
Old 12-22-2007, 05:24 PM   #2 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Interesting, this seems to be a whole lot simpler than generally connecting to MySQL, which you must insert "mysql_select_db" for selection of the database, a lot simpler! Thanks.
Orc is offline  
Reply With Quote
Old 12-22-2007, 08:00 PM   #3 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

woot?!

Quote:
Originally Posted by Matt83
mysqli is the "new" extension provided in PHP5
mysqli has been a PHP extension since PHP4.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 12-22-2007, 08:10 PM   #4 (permalink)
The Contributor
Upcoming Programmer 
 
Matt83's Avatar
 
Join Date: Oct 2007
Location: Argentina
Posts: 72
Thanks: 18
Matt83 is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
woot?!



mysqli has been a PHP extension since PHP4.
yes, hence the quotes around it.. "new"
__________________
http://www.mattvarone.com
Matt83 is offline  
Reply With Quote
Old 12-22-2007, 11:52 PM   #5 (permalink)
bdm
The Acquainted
Good Samaritan 
 
Join Date: Nov 2007
Posts: 127
Thanks: 14
bdm is on a distinguished road
Default

It's also worth mentioning that mysqli will only protect against SQL injection if you use prepared statements.

I was going to write a tutorial about the basics of using the mysqli extension. But why write one when Zend has already done an outstanding job?

Part I - Overview and Prepared Statements
Part II - Extending mysqli
bdm is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:22 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design