[Vtigercrm-developers] Day 3: Modernizing your database handling

Holbok István holbok at gmail.com
Sun Dec 4 10:35:13 GMT 2016


Yesterday you learned *Modernizing your codebase*. Today we're going to
dive into *Modernizing your database handling*.

Are you still writing plain sql statements and running them with
mysql_query ? If so, your codebase must have been hacked before. I would
be surprised if it hasn't. No? Tell us your URL, we will delete your
data right away. That is how easy it is to hack a MySQL extension
powered PHP application.

Jokes aside, the truth is that the PHP MySQL extension is depreciated,
you should avoid it at all costs.

Currently two main extensions in PHP for dealing with databases. One is
MySQLi (MySQL improved) and the other is PDO (PHP Data Objects). These
extensions are similar in that they both support almost all the database
operations, such as insert, delete, update, database transaction, real
escape string and so on.

However we recommend using PDO to build your applications due to the
following two reasons:

  *  It enables developers to write portable code. 
  * It encourages object-oriented programming.

PDO is built with database drivers besides MySQL. Currently it supports
more than ten databases including MS SQL, Oracle, PostgreSQL, SQLite and
so on. This is really powerful, because we can write our code once and
let it run on different types of database engines. We do not need to
change even a single line of code.

Object-oriented programming (OOP) also plays a big part in our decision
to choose a database access library. At the end of the day, we want our
codebase to be easy to change, and we believe that OOP allows us to do
that. Time to pick up PDO and have your next project run safely.
 
Now that you understand the importance of using PDO, tomorrow's
installment will dive into *Error handling*.

Until then,
 
Keep learning!
Xu
www.startutorial.com
Kindest regards:
Istvan Holbok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20161204/4a522a36/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open
Type: image/gif
Size: 43 bytes
Desc: not available
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20161204/4a522a36/attachment.gif>


More information about the vtigercrm-developers mailing list