Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2013, 05:55 PM   PM User | #1
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
MYSQLI Advise - Help ETC..

What are the benifits to MYSQLI than MYQSL?

What are the new items you can do that you could not do with MYSQL


How should the queries look in MYSQLI compared to MYSQL..

How soon should we change to this?


Thanks.. Slayer.
SlayerACC is offline   Reply With Quote
Old 02-06-2013, 06:05 PM   PM User | #2
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
There are numerious improvements over Mysql including security, function application as well as result improvement.

The problem with listing all the features here in your post is that Mysql is going away regardless if anyone likes it or not. So unless your host is planning to stay on PHP5.4 or below you WILL have to do this eventually regardless of any benefits.

I personally dont know when they plan to release it, PHP 5.5 is just now in Alpha so it will be awhile im guessing. I personally am planning for inside 2 years. Which will pass quicker than you think.

Luckily i am with a host that i do some work for (barter) and they have agreed to hold off updating to 5.5 even after release to make sure their scripts and customers scripts are updated first. Most dont have that option and you may find yourself in a corner, so i would suggest starting now. Just my opinion.

also read this thread, good info..
http://www.codingforums.com/showthread.php?t=287124

Last edited by durangod; 02-06-2013 at 06:10 PM..
durangod is offline   Reply With Quote
Users who have thanked durangod for this post:
SlayerACC (02-06-2013)
Old 02-06-2013, 06:32 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The simplest change from mysql_ to mysqli_ involves adding the 'i' into the function name and swapping the two parameters around the other way (or adding the database parameter if you were leaving it out.

You can then apply all the enhanced features when you are ready. These include

- Being able to use mysqli_ calls in an object oriented way.
- Being able to keep the SQL and data separate by using PREPARE and BIND instead of QUERY

You should get rid of all the mysql_ references as quickly as possible so that you can start applying the additional security features and so better protect your database from attack. It doesn't take long to do a basic conversion - an hour should suffice to convert a few hundred web pages. Actually applying the new features will take longer but you can do that a call at a time once you have converted across.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
SlayerACC (02-06-2013)
Old 02-06-2013, 06:54 PM   PM User | #4
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Thank you for your quick replies..

I understand the change will happen regardless... as you know change is not always our friend...

In this case I ask if you can give examples of a connect to the database, a select and a count of such.

I currently have about 5 or 6 sites that I have to start with the change over to the new MYSQLI however.. I want to try to make this a seem less as possible.

for example: mysql
PHP Code:
$results mysql_query("SELECT * FROM TABLE")
or die(
mysql_error());

while(
$row mysql_fetch_array$results )) {

echo 
$row['name'];


Example 2: MYSQLI
PHP Code:
$result $mysqli->query("SELECT * FROM TABLE");
while (
$row $result->fetch_assoc()) {


echo 
$row['name'];


What would this be in MYSQLI?
PHP Code:
or die(mysql_error()); 
Would it be this
PHP Code:
or die(mysqli_error()); 

Man Change Sucks!!!

How do we support the other items such as count, search pages etc?

Thanks, Slayer
SlayerACC is offline   Reply With Quote
Old 02-06-2013, 06:57 PM   PM User | #5
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
Procedural:

PHP Code:
mysqli_error($link
$link being new mysqli(...);
TFlan is offline   Reply With Quote
Users who have thanked TFlan for this post:
SlayerACC (02-06-2013)
Old 02-06-2013, 07:18 PM   PM User | #6
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Yep TFlan is correct remember SlayerACC that in many cases now you need to add the db link where you did not require it before. Some of it depends on how you perform the task, if you use statments or if you stick with object oriented or stay with procedural style.

The way i understand it, in general if you use statments then you need to open the statement, bind (prepare)the statement, execute the statement, then close the statement each time you use it.

have a look at this

http://www.php.net/manual/en/mysqli....statements.php

there are certainly benefits to having more controls over the process but i chose to stick with object oriented simply because it was quicker and because in my small scripts some of the NON benefits really did not hurt me or the process. So it was just the best call for me.

What i mean by object oriented for me anyway (i guess its actually proceedural) but i like to think of it is object because i have an object result) is this, lets take your example of Mysql and convert it the way i did to MySQLi procedural style



Your example:

PHP Code:

$results 
mysql_query("SELECT * FROM TABLE"
or die(
mysql_error()); 

while(
$row mysql_fetch_array$results )) { 

echo 
$row['name']; 


Here is the conversion the way i did it.

PHP Code:

$query 
"SELECT * FROM TABLE"
$results mysqli_query($link,$query)or die(mysqli_error($link)); 

while(
$row mysqli_fetch_array$results )) { 

echo 
$row['name']; 


Hope that helps

Last edited by durangod; 02-06-2013 at 08:30 PM.. Reason: forgot the i in error lmao and had to clarify what i consider object oriented for me
durangod is offline   Reply With Quote
Old 02-06-2013, 07:41 PM   PM User | #7
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
Please do not take what Durangod has said about his code being object oriented to mind.

It is not.

He is using the procedural style, just as you are, NOT object oriented style of the mysqli library.
TFlan is offline   Reply With Quote
Old 02-06-2013, 08:18 PM   PM User | #8
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
Quote:
Originally Posted by TFlan View Post
Please do not take what Durangod has said about his code being object oriented to mind.

It is not.

He is using the procedural style, just as you are, NOT object oriented style of the mysqli library.
I also stated i considered it object oriented for me in my mind and i explained what i meant by that. I guess i could have shown him without that explaination and just left all that out and just put the code, but in my case my object thinking comes from the old coding practices way before the internet and i still think that way even if it is not the Technical term for it now.

Sorry for the confusion..
durangod is offline   Reply With Quote
Old 02-06-2013, 08:38 PM   PM User | #9
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
I understand where you are coming from, but for the sake of explanation, that could confuse the OP. Especially in this case with the new library the OP is learning
TFlan is offline   Reply With Quote
Old 02-06-2013, 09:49 PM   PM User | #10
SlayerACC
Regular Coder

 
Join Date: Sep 2009
Location: Calgary, Alberta
Posts: 222
Thanks: 45
Thanked 3 Times in 3 Posts
SlayerACC is an unknown quantity at this point
Thanks for the explaination.

You guys are alot of help... thanks.

Looking to put some of this to work today... starting a new site and needed to get this figured..

Slayer.
SlayerACC is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:48 AM.


Advertisement
Log in to turn off these ads.