Solved

mysqli vs mysql?

Posted on 2009-07-03
4
1,039 Views
Last Modified: 2013-12-13
I'm reading a PHP book. He is using mysqli_query etc.

Why is that?

I'm using mysql_query. Should I stick to it?
0
Comment
Question by:AphX
4 Comments
 

Accepted Solution

by:
Naveed_Manzoor earned 250 total points
Comment Utility
MySQLi is new extension whose major goals are
"      Easier maintainability The ext/mysql code base has become somewhat complex and messy. Major enhancements in the functionality of MySQL required that various feature sets be enabled or disabled based on the version of the client library. Other issues required that some features be disabled for particular operating systems.
"      Better compatibility The extension needed to conform more closely to the MySQL client library, so that future enhancements to the library could be supported more easily in PHP
"      Backwards compatibility Although the compatibility between ext/mysql and ext/mysqli is not perfect, effort was made to simplify porting applications from ext/mysql to ext/mysqli.

Major Features
"      A procedural interface that looks very much like the ext/mysql interface
"      An object-oriented interface that allows for a use idiom that is both more convenient and easier to extend than the procedural interface
"      Support for the new MySQL binary protocol that was introduced in MySQL 4.1. (The new protocol is more efficient that the old one and allows for the support of a broader range of features, such as prepared statements.)
"      Support for the full feature set of the MySQL C client library, including the ability to set advanced connection options via mysqli_init() and related functions.
Additionally, the extension has support for additional tracing debugging, load balancing and replication functionality

Why Switch?
Beyond gaining access to the new features of MySQL 4.1+, why would anyone want to switch to using ext/mysqli?

In addition to the functionality mentioned above, ext/mysqli also has some other serious benefits:
"      Greater speed. Enhancements in both the extension and in MySQL have made most operations faster, with certain operations becoming up to 40 times faster as compared to ext/mysql.
"      Better security. In older versions of the MySQL RDBMS, the possibility existed for an attacker to extract weak password hashes from the network and then recreate a user's password. The new authentication procedure is much more robust and mirrors the attack-resistant authentication procedure of tools like SSH.

ONLY THING I DONT LIKE :
Still not able to find way to echo or debug prepared statements .

0
 
LVL 7

Assisted Solution

by:szewkam
szewkam earned 250 total points
Comment Utility
read this, it should clarify :)
http://pl.php.net/manual/en/mysqli.overview.php
0
 
LVL 39

Expert Comment

by:Roger Baklund
Comment Utility
The "i" in mysqli stands for "improved". mysqli is a newer implementation of the mysql client library in php.

mysqli have some features not available in the standard php "mysql" client library. Most notably, it is object oriented and supports prepared statements. Using prepared statements is more secure.

Most tutorials and php/mysql scripts you find on the net will be using the older mysql_* functions. This is one reason to stick with this.

Except for the improvements in mysqli, the two library implementations are quite similar. Most of the old mysql_ functions also exists as a mysqli_ function. Learning to use one of these will to some degree also teach you to use the other.

My advice: learn both. Focus on mysqli, but experiment with the classic mysql_ functions also, so that you know how to use it and how to modify old code you might come across.
0
 
LVL 5

Expert Comment

by:Opalelement
Comment Utility
MySQLi requires an additional PHP extension.

The only differences I know of are that MySQLi has multi_query, you have to give the link resource in each query, and it escapes strings for you.

I have read in many different places that MySQLi is faster, but the test results I see point to MySQL.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now