[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

mysqli vs mysql?

Posted on 2009-07-03
4
Medium Priority
?
1,075 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to count occurrences of each item in an array.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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