473,378 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Should I use mysql, mysqli or PDO?

Hi,

What should I be using for general MySQL database access? I've been
using the traditional mysql extension for ages, but I'm trying to
update my style to a more OOP paradigm.
I've used PDO briefly but I've not used the mysqli extension yet.
I've read a bit about it though, seems good and more OOP orientated
(for the most part). But PDO seems more generic and transferable.

Any comments?
TIA

Nov 4 '07 #1
11 11057
..oO(macca)
>What should I be using for general MySQL database access? I've been
using the traditional mysql extension for ages, but I'm trying to
update my style to a more OOP paradigm.
I've used PDO briefly but I've not used the mysqli extension yet.
I've read a bit about it though, seems good and more OOP orientated
(for the most part). But PDO seems more generic and transferable.
Use PDO if available.

Micha
Nov 4 '07 #2
macca wrote:
Hi,

What should I be using for general MySQL database access? I've been
using the traditional mysql extension for ages, but I'm trying to
update my style to a more OOP paradigm.
I've used PDO briefly but I've not used the mysqli extension yet.
I've read a bit about it though, seems good and more OOP orientated
(for the most part). But PDO seems more generic and transferable.

Any comments?
TIA

If I'm going to be using only mysql, I use the mysqli classes. I like
the way they're designed and it has less overhead than PDO.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 4 '07 #3
On Nov 4, 1:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
macca wrote:
Hi,
What should I be using for general MySQL database access? I've been
using the traditional mysql extension for ages, but I'm trying to
update my style to a more OOP paradigm.
I've used PDO briefly but I've not used the mysqli extension yet.
I've read a bit about it though, seems good and more OOP orientated
(for the most part). But PDO seems more generic and transferable.
Any comments?
TIA

If I'm going to be using only mysql, I use the mysqli classes. I like
the way they're designed and it has less overhead than PDO.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I've written my own database class using PHP's mysql functions, rather
than using mysqli, and I've added functions to automatically get,
insert and update. In the end, it's a lot faster than the built-in
mysqli, and it didn't take long to write.

Nov 5 '07 #4
On Mon, 05 Nov 2007 09:20:08 +0100, <ja***@jgoode.co.ukwrote:
On Nov 4, 1:51 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>macca wrote:
Hi,
What should I be using for general MySQL database access? I've been
using the traditional mysql extension for ages, but I'm trying to
update my style to a more OOP paradigm.
I've used PDO briefly but I've not used the mysqli extension yet.
I've read a bit about it though, seems good and more OOP orientated
(for the most part). But PDO seems more generic and transferable.
Any comments?
TIA

If I'm going to be using only mysql, I use the mysqli classes. I like
the way they're designed and it has less overhead than PDO.
I've written my own database class using PHP's mysql functions, rather
than using mysqli, and I've added functions to automatically get,
insert and update. In the end, it's a lot faster than the built-in
mysqli, and it didn't take long to write.
There's one major advantage of mysqli though: real prepared statements.
PHP doesn't know everything about the MySQL server, so escaping string can
be tricky business (especially with 'broken' Unicode, there's a very slim
possibility a quote will appear where there was none). Prepared statements
free you from that headache.
--
Rik Wasmus
Nov 5 '07 #5
..oO(ja***@jgoode.co.uk)
>I've written my own database class using PHP's mysql functions, rather
than using mysqli, and I've added functions to automatically get,
insert and update.
The old MySQL extension misses some really important features like
prepared statements and native transaction support.
>In the end, it's a lot faster than the built-in
mysqli, and it didn't take long to write.
Did you test that? Your wrapper class is written in PHP, while the
MySQLi and PDO extensions are written in C and directly call the MySQL
API. Of course there will be some overhead because of the advanced
features (especially in PDO), but I doubt that this makes much of a
difference. What really counts are the queries sent to the DB and the
table structure, not the used interface (IMHO).

Micha
Nov 5 '07 #6
Greetings, Rik Wasmus.
In reply to Your message dated Monday, November 5, 2007, 11:42:54,
PHP doesn't know everything about the MySQL server, so escaping string can
be tricky business (especially with 'broken' Unicode, there's a very slim
possibility a quote will appear where there was none). Prepared statements
free you from that headache.
Sorry, but... what mysql_real_escape_string function does then?
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Nov 6 '07 #7
On Nov 6, 6:37 am, AnrDaemon <anrdae...@freemail.ruwrote:
Greetings, Rik Wasmus.
In reply to Your message dated Monday, November 5, 2007, 11:42:54,
PHP doesn't know everything about the MySQL server, so escaping string can
be tricky business (especially with 'broken' Unicode, there's a very slim
possibility a quote will appear where there was none). Prepared statements
free you from that headache.

Sorry, but... what mysql_real_escape_string function does then?

--
Sincerely Yours, AnrDaemon <anrdae...@freemail.ru>
the *_real_escape_string family get the encoding they're supposed to
escape from mysql while connecting, if you happen to set mysql to
another encoding (and in some edge cases just in php) you might not
get the string you expected in mysql. That's what Wasmus was talking
about, when he mentioned there's a chance of a quote appearing where
you didn't expect it.

A user might put a character that's supposed to be a in cp1251, but
is a ' in some Uganda encoding. You happen to be in uganda and you
happen to not use true UTF, so you do some encoding switching. Worst
case scenario - maybe a table will be dropped. Hackers on the other
hand try huge amounts of possible sql injections. If there's a weak
spot, they're bound to find it sooner or later.

If you're keen on using the mysql extension, make suer everything you
do is true unicode, but there's still the chance you happen to forget
to escape something, somewhere, somethime.

Nov 6 '07 #8
Greetings, NoDude.
In reply to Your message dated Tuesday, November 6, 2007, 12:25:08,
PHP doesn't know everything about the MySQL server, so escaping string can
be tricky business (especially with 'broken' Unicode, there's a very slim
possibility a quote will appear where there was none). Prepared statements
free you from that headache.

Sorry, but... what mysql_real_escape_string function does then?
the *_real_escape_string family get the encoding they're supposed to
escape from mysql while connecting, if you happen to set mysql to
another encoding (and in some edge cases just in php) you might not
get the string you expected in mysql. That's what Wasmus was talking
about, when he mentioned there's a chance of a quote appearing where
you didn't expect it.
A user might put a character that's supposed to be a in cp1251, but
is a ' in some Uganda encoding. You happen to be in uganda and you
happen to not use true UTF, so you do some encoding switching. Worst
case scenario - maybe a table will be dropped. Hackers on the other
hand try huge amounts of possible sql injections. If there's a weak
spot, they're bound to find it sooner or later.
If you're keen on using the mysql extension, make suer everything you
do is true unicode, but there's still the chance you happen to forget
to escape something, somewhere, somethime.
Example? I can't understand what You talking about.

If I working with *_real_escape_string, it is for sure escaping characters
which would cause damage to SQL statement in current SQL encoding.
Not related to encoding PHP uses. It is just thing from different world.

So then, if someone supplied a string in any encoding, it is only byte array
while passed to escaping function.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Nov 6 '07 #9
AnrDaemon wrote:
Greetings, NoDude.
In reply to Your message dated Tuesday, November 6, 2007, 12:25:08,
>>>PHP doesn't know everything about the MySQL server, so escaping string can
be tricky business (especially with 'broken' Unicode, there's a very slim
possibility a quote will appear where there was none). Prepared statements
free you from that headache.
Sorry, but... what mysql_real_escape_string function does then?
>the *_real_escape_string family get the encoding they're supposed to
escape from mysql while connecting, if you happen to set mysql to
another encoding (and in some edge cases just in php) you might not
get the string you expected in mysql. That's what Wasmus was talking
about, when he mentioned there's a chance of a quote appearing where
you didn't expect it.
>A user might put a character that's supposed to be a in cp1251, but
is a ' in some Uganda encoding. You happen to be in uganda and you
happen to not use true UTF, so you do some encoding switching. Worst
case scenario - maybe a table will be dropped. Hackers on the other
hand try huge amounts of possible sql injections. If there's a weak
spot, they're bound to find it sooner or later.
>If you're keen on using the mysql extension, make suer everything you
do is true unicode, but there's still the chance you happen to forget
to escape something, somewhere, somethime.

Example? I can't understand what You talking about.

If I working with *_real_escape_string, it is for sure escaping characters
which would cause damage to SQL statement in current SQL encoding.
Not related to encoding PHP uses. It is just thing from different world.

So then, if someone supplied a string in any encoding, it is only byte array
while passed to escaping function.

That is true. mysql_real_escape_string() should prevent problems with
strings using the current encoding.

Now, it may not be the encoding you *want* - but there shouldn't be any
problems inserting or updating data using it. At least barring any bugs
in the function, of course :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 6 '07 #10
On Nov 5, 8:48 am, Michael Fesser <neti...@gmx.dewrote:
.oO(ja...@jgoode.co.uk)
I've written my own database class using PHP's mysql functions, rather
than using mysqli, and I've added functions to automatically get,
insert and update.

The old MySQL extension misses some really important features like
prepared statements and native transaction support.
In the end, it's a lot faster than the built-in
mysqli, and it didn't take long to write.

Did you test that? Your wrapper class is written in PHP, while the
MySQLi and PDO extensions are written in C and directly call the MySQL
API. Of course there will be some overhead because of the advanced
features (especially in PDO), but I doubt that this makes much of a
difference. What really counts are the queries sent to the DB and the
table structure, not the used interface (IMHO).

Micha
Just to clarify my previous post; by faster, I meant the process of
writing code is faster, not the speed at which database actions are
performed, for instance, my class includes a 'get' function, and
$array = data::get('blog_entries') would fetch all of the posts in the
table blog_entries.

Nov 6 '07 #11
..oO(ja***@jgoode.co.uk)
>Just to clarify my previous post; by faster, I meant the process of
writing code is faster
OK, now it makes sense.
>not the speed at which database actions are
performed, for instance, my class includes a 'get' function, and
$array = data::get('blog_entries') would fetch all of the posts in the
table blog_entries.
I've similar functions in my own DB class, which is an extension of the
PDO class.

Micha
Nov 6 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: j-marvin | last post by:
hi- i have a book on mysql written for version 4 that has hard to read screen shots. i'd like to get a newer mysql book. do i have to worry about the version number of mysql i am using if i use...
2
by: NevrGivUp | last post by:
Hello. I am in the process of learning php. I am particularly interested in its uses with MySQL. I have Apache 2 and PHP5 both installed and working fine. I pasted a MySQLi example for opening...
0
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
5
by: php-newbe | last post by:
I can conntect to mySQL thouth the mySQL monitor, but I cannot access it thorugh php script. After PHP5 installation I had uncommented "extention_php_mysql.dll" in php.ini file. I copied...
7
by: Paul | last post by:
I recently installed php 4.4.4 using windows binaries on Windows XP Pro. I also installed MySQL 4.1. I usually use Pear DB but I tried MDB2 and it worked fine until a client uses a different...
3
by: yes_its_just_me | last post by:
Hi everyone, I haven't used PHP since version 4 and am trying to use it for a new project. All I'm trying to do is connect to a MySQL database and show the contents of that database (as a start)....
9
by: christopher_board | last post by:
Hi all. I am trying to write a php page which connects to a MySQL Database which is supposed to get the results from a table within a database and display the results in a table. Below is the...
1
by: chanshaw | last post by:
Alright so I got php running and installed i have mysql running and installed the thing im having a hard time with is having the php to call information from the mysql database. Im on Windows Vista...
3
code green
by: code green | last post by:
I am still using the mysql extension rather than the mysqli. Moving to mysqli would be realively simple in my case because all mysql_ procedural calls are wrapped in a class MySqlDB(). As are...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.