?
Solved

mysqli vs mysql?

Posted on 2009-07-03
4
Medium Priority
?
1,065 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Accepted Solution

by:
Naveed_Manzoor earned 1000 total points
ID: 24774208
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 1000 total points
ID: 24774209
read this, it should clarify :)
http://pl.php.net/manual/en/mysqli.overview.php
0
 
LVL 39

Expert Comment

by:Roger Baklund
ID: 24774227
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
ID: 24774228
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses

770 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