Should I keep using the normal mysql_query or switch to PDO interface in php?

I’m building a big website, and using the normal old mysql_query method for transactions and communications with the database, and everything i going fine, including security. I’m a little bit confused, should I switch to the new PDO interface? cause I learnt that’s safer, or keep using the old mysql_query() and mysql_fetch_assoc() methods?

I’m very close to completing the website, and to switch to the PDO interface will cost me time, to start updating my codes.

I’m a little confused, which should I use and what are the pros and cons?

2

I’m a little confused, which should i use

No doubt if you just go through this link you will see a notice. So you should get switched to PDO or MySQLi.

Cons and Pros :

There are many posts available on stackoverflow on this subject. They all talk about PDO and why use it.

  • one
  • two
  • three
  • four

And many more here. Finally I would recommend you to switch to PDO or mysqli as mysql will be removed as per the link. Even if you have considered the security issues and secured you app, whats the use when it is completely lost? You need to do it later time somehow, So do it now itself. Hope this helps.

Normally it’s good to use the Mysqli or PDO is the best option for connecting database, since mysql will be removed soon.

But in developer point of view, write a simple wrapper class for all database connectivity

For example

For mysql

Class database_mysql {
     public getResults($query) {
         $result = mysql_query($query);
         $row = mysql_fetch_assoc($result);
         return $row;
      }
.
.
.
<other functions>
}

For PDO

Class database_pdo {
     public getResults($query) {
        $statement = $pdo->query($query);
        $row = $statement->fetch(PDO::FETCH_ASSOC);
        return $row;
      }
.
.
.
<other functions>
}

For mysqli

Class database_mysqli {
     public getResults($query) {
        $result = $mysqli->query($query);
        $row = $result->fetch_assoc();
        return $row;
      }
.
.
.
<other functions>
}

when you initialize the class use below

$db = new Database_mysql(<arguments>);

where ever you need the results, just use

$db->getResults(<query>);

if you need to switch over to mysqli, or PDO, just change the class name

$db = new Database_pdo(<arguments>);

So this will save lot of your time on changing the extension.

1

I would prefer PDO for any new development, as its a pretty nice interface and supports most backend databases without to much fiddling (with the notable exception of ORACLE!).

However if you a a functioning system using ‘mysql_query’ then I don’t see any reason to change. The main advantage of PDO apart from portability is that its a nice clean interface to code up. But as your application is already coded and you do not intent to switch from MySql to another DB I think your time would be better spent doing something more useful.

You can still work with your code provided you don’t plan upgrading to the version(s) of php that will take mysql out.
Which means you’ll loose most of the improvements in these new version(s).

Switching from mysql to mysqli will be easier as compared to pdo, mysqli have similar interface/functions to mysql.

If you intend to connect to only mysql databases, then i would advise you to use mysqli, pdo is more generic and allows you to connect to other databases with minimal changes, but I think there will be a performance loss as compared with mysqli.
I must admit though that its unnoticeable.

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật