Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,209,046 members, 8,004,700 topics. Date: Sunday, 17 November 2024 at 12:26 AM

Pros $ Cons Of PDO And Mysqli - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Pros $ Cons Of PDO And Mysqli (7077 Views)

What Are The Pros And Cons Of Using An Online Payment Gateway / What Are The Pros And Cons Of Sharing Adsense With A Friend / Pros And Cons Of Buying Facebook Likes & Twitter Followers (2) (3) (4)

(1) (2) (Reply) (Go Down)

Pros $ Cons Of PDO And Mysqli by osile2012: 5:54pm On May 04, 2015
Developers can choose to connect to the SQL database with either the PDO or Mysqli extension. those who still use mysql are advised to change it to mysqli as it is deprecated and will no longer be supported or recognized soon.

However, when choosing which database extension to use, you should consider these few points.

PDO is supported by more than 7 different databases, while Mysqli is only supported by mysql.

PDO is purely object oriented while mysqli is both object oriented and procedural . This means that people who are not yet familiar with object oriented programing, can use mysqli but not PDO.

PROBLEM.

There is a big problem you will likely face, when using Mysqli prepared statements. This is getting result from a prepared statement.

You can say
$stmt=myqli->prepare( "select from bla bla bla where bla bla is = bla bla"wink;
$tmt->bind_param(ss,bla bla bla);
stmt->execute();

Now this is lovely abi ?

Now to get the result from this statement, assuming you need to compare the values for authentication or something, you simply type

$info=$stmt->get_result();

Thats all, it gets the result and put it in info for u to us. {{BAD NEWS}}, some or most basic hosting packages will not support this. Most basic hosting packages will not have more than php.5.3 installed, so you wont be able to get that result back this way. They will tell you to upgrade to a cloud host, where you will have the ability to install whatever version you like. Dont see the price.

Now when you get this sad news, to go back to retrieve that result the other way, is so stressful. You will have to use bind result function first, after that you specify the column names, you want the results to be bound to. Assuming you had up to 10 columns, you have to start specifying them one by one. Before you finish one function you don write up to 10000000000 codes.

You might just forget about getting result from prepared statements and dont use them at all if getting result is required. However this makes ur app vulnerable to attacks.


PDO handles this very simply without stress. But there is also a problem you will face with pdo as you work. Will talk about it in my next post.

If you feel, this has been useful, click the link on my signature, rate top brands, products and people in naija grin grin grin

5 Likes 1 Share

Re: Pros $ Cons Of PDO And Mysqli by OmniPotens(m): 6:28pm On May 04, 2015
@OP Have you ever heard about
mysqli_fetch_object()
?

1 Like

Re: Pros $ Cons Of PDO And Mysqli by osile2012: 6:37pm On May 04, 2015
OmniPotens:
@OP Have you ever heard about
mysqli_fetch_object()
?

[size=15pt]No. Please what is it for, and how can it be used to get result from a "prepared statement" after execution ?.[/size]
Re: Pros $ Cons Of PDO And Mysqli by maekhel(m): 7:05pm On May 04, 2015
osile2012:

PDO is supported by more than 7 different databases, while Mysqli is only supported by sql
@ the bold
Re: Pros $ Cons Of PDO And Mysqli by mekaboy(m): 7:35pm On May 04, 2015
maekhel:

@ the bold

I am sure the op means driver support and meant mysql instead of sql. And he would be right about that.

1 Like

Re: Pros $ Cons Of PDO And Mysqli by maekhel(m): 7:48pm On May 04, 2015
mekaboy:

mysql instead of sql.
My point
Re: Pros $ Cons Of PDO And Mysqli by osile2012: 8:37pm On May 04, 2015
maekhel:

@ the bold

[size=15pt]Thanks for pointing that out. Corrected.. grin grin.[/size]
Re: Pros $ Cons Of PDO And Mysqli by osile2012: 8:10am On May 06, 2015
As i promised earlier, let me share a problem you will face with PDO.

After you have selected items from a database, its not possible to count the number of rows returned with PDO. This seems to be a big issue. Assuming your next action will depend on the number of rows returned, There is no way to count rows with PDO. Mysqli has the fetch_row and num_rows function to handle that but PDO hasnt .

SOLUTION

You have to run the exact query but this time use count. E.G " select count(*) from bla bla where bla bla = bla ba ". Then run the query like $counter=$dbh->query($query);

To get the number of rows returned

$numrows=$counter->fetchcolumn();

This is the way you can get the number of rows.

1 Like

Re: Pros $ Cons Of PDO And Mysqli by naijainfogalery: 11:14am On May 06, 2015
i just love nairaland, learning new things
Re: Pros $ Cons Of PDO And Mysqli by okooloyun1(m): 11:15am On May 06, 2015
Sekem out of thread don't understand what op dey talk.
Re: Pros $ Cons Of PDO And Mysqli by jamex93(m): 11:15am On May 06, 2015
ok
Re: Pros $ Cons Of PDO And Mysqli by Abayor7: 11:16am On May 06, 2015
I just scored a hat trick of FP


brb
Re: Pros $ Cons Of PDO And Mysqli by Nobody: 11:17am On May 06, 2015
This thread reminds me of C#. grin
Re: Pros $ Cons Of PDO And Mysqli by ellaV(m): 11:18am On May 06, 2015
Who cares kiss[sup][/sup] undecided[color=#990000][/color]
Re: Pros $ Cons Of PDO And Mysqli by Nobody: 11:19am On May 06, 2015
php is to python what mysql is to postgresql

1 Like

Re: Pros $ Cons Of PDO And Mysqli by boolet: 11:20am On May 06, 2015
What's this? Omo, wetin man no know, man no know.
Re: Pros $ Cons Of PDO And Mysqli by haxorDelite(m): 11:20am On May 06, 2015
so what exactly are u driving @, is it because mysqli has that issue so we should switch to PDO or what??
Re: Pros $ Cons Of PDO And Mysqli by pretydamsel1(f): 11:22am On May 06, 2015
how is this my business huh!!
Re: Pros $ Cons Of PDO And Mysqli by intergral(m): 11:22am On May 06, 2015
Ok.... Still learning python...
Re: Pros $ Cons Of PDO And Mysqli by eazysally: 11:23am On May 06, 2015
Wetin dem dey talk here sef, I thought I saw DPO and NYPD
Re: Pros $ Cons Of PDO And Mysqli by chupcake(m): 11:25am On May 06, 2015
I be DB Administrator... Make I just dey observe
Re: Pros $ Cons Of PDO And Mysqli by akereconfi: 11:34am On May 06, 2015
@OP

if($stmt->execute()){

()

}
Re: Pros $ Cons Of PDO And Mysqli by ClintonNzedimma(m): 11:45am On May 06, 2015
Hmmm
Re: Pros $ Cons Of PDO And Mysqli by ITbomb(m): 11:46am On May 06, 2015
The poster below me sha grin
I doubt if he knows what he is talking about

1 Like

Re: Pros $ Cons Of PDO And Mysqli by faray: 11:46am On May 06, 2015
i love pdo i hate mysql
Re: Pros $ Cons Of PDO And Mysqli by Atmmachine(m): 11:47am On May 06, 2015
Make Una no sell person here
Re: Pros $ Cons Of PDO And Mysqli by lordjay: 12:25pm On May 06, 2015
osile2012:
As i promised earlier, let me share a problem you will face with PDO.

After you have selected items from a database, its not possible to count the number of rows returned with PDO. This seems to be a big issue. Assuming your next action will depend on the number of rows returned, There is no way to count rows with PDO. Mysqli has the fetch_row and num_rows function to handle that but PDO hasnt .

SOLUTION

You have to run the exact query but this time use count. E.G " select count(*) from bla bla where bla bla = bla ba ". Then run the query like $counter=$dbh->query($query);

To get the number of rows returned

$numrows=$counter->fetchcolumn();

This is the way you can get the number of rows.




OP, except i don't understand what you're talking about, but I use rowCount() to fetch number of rows in PDO and it works perfectly for me.
Re: Pros $ Cons Of PDO And Mysqli by wethebest(m): 12:29pm On May 06, 2015
how do you convert your alrdy existing MySQL script to mysqli?
Re: Pros $ Cons Of PDO And Mysqli by lordjay: 12:34pm On May 06, 2015
wethebest:
how do you convert your alrdy existing MySQL script to mysqli?

Very simple (being sarcastic), just rewrite all your queries with mysqli syntax or you could just try PDO at once being the latest and most robust

(1) (2) (Reply)

The Scammer Princeogun -- Webmasters Judge Us / SEO 101: Definitive SEO Guide For Start-ups / Get Free 7.5gb Data From Mtn

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.