It's free. Join us, If you care enough to read the content, post news, stories, add or answer questions on Everyknows.

Log in or Sign Up with your EveryKnows account
By continuing you indicate that you have read and agree to Everyknows
Terms of Use and Privacy Policy.

© EveryKnows Inc 2018

Welcome to Every Knows

Join the conversation... let's make the world more open and connected.

There's more to discover

"If we would have a new knowledge, we must get a whole world of new questions."
See the best answers from Every Knows..

Hi Guest!! What's on your mind?
Why PHP in PDO?

i'm still a newbie, just finished Web design class few weeks ago, and lucky for me I built a site for a client that pays peanut. Later a friend of mine told me to migrate to pdo, I don't get the reason why I should do so. I have already built a private website for a client.

This is my first time of hearing php pdo from him. So I want to know Is there any need to move to pdo
0 0 4

Answered: Aigbe Marvellous 4 months ago

PHP can be used anywhere, but using PHP enhances the PD

0 0 share
Answered: Jessie Priscilla 4 months ago

I don't really know but PHP is advisable to use in PD

0 0 share
Answered: Marvellous Ebi 4 months ago

PDO makes it easier to write code in PHP statement. It I should an easier way to write codes comfortably. It should be linked to the PH

0 0 share
Answered: obicheozo emeka 4 months ago
Studied Computer Science at Imo State University Owerri . Interested in Artificial Intelligent, Mobile Applications, Sports and Politics

PHP Data Object (PDO) is more secure than the normal PHP in MYSQL and MYSQLi. there are lots of security measures in PDO prepared statement and many more functionalities. Below are some of the features why most developers are migrating to PDO

1. Database support
The PDO extension has the capability to access any database which the PDO driver has been written for. There are many PDO drivers available, a few of which include PDO drivers meant to access Free TDS, Sybase, Microsoft SQL Server, IBM DB2, Firebird/Interbase 6, Oracle Call Interface and PostgreSQL databases, among many more.

The drivers are not automatically available in every system, so you will have to find your available drivers and add the ones that you need.
Database connecting

There are different syntaxes to establish database connections which depend on specific databases. When using PDO, you want to ensure that your operations are wrapped in try/catch blocks and that you utilise the exception technique.

In normal cases, only a single connection need be made, and connections are closed by programming the database handle as a null. You can look up more specific options and syntaxes in various resource sites.

2. Error handling
PDO allows for the use of exceptions for error-handling, which is why you’re advised to wrap PDO in try/catch blocks. This way, PDO can be forced into the relevant error mode attribute in order to produce an exception.

There are three – silent (default), warning and exception – modes. The latter two are more useful in DRY programming. ‘Warning’ error mode is useful for debugging and the ‘exception’ mode allows graceful error handling while hiding data that a person might use to exploit your system.

3. Inserts and Updates
PDO condenses the common insert and update database operations into a simple two-step process: Prepare >> [Bind] >> Execute. With this method, you can take full advantage of PDO’s prepared statements, which offer you protection against malicious attacks through SQL injection.

Prepared statements are pre-complied SQL statements which may be executed several times by sending this data to the servers. They are advantageous in that data used within the placeholders is automatically protected from SQL injection attacks.

There are many more features of PDO that make it superior to both MySQL and MySQLi; the above are only a tip of the iceberg. While MySQL was a useful tool in its time, no doubt it has been overtaken by the superiority of PDO objects, and PHP programmers would be better served by adopting this approach going forward.

PDO offers you a choice of 3 different error handling strategies, to fit your style of application development.


This is the default mode. PDO will simply set the error code for you to inspect using the PDO::errorCode() andPDO::errorInfo() methods on both the statement and database objects; if the error resulted from a call on a statement object, you would invoke the PDOStatement::errorCode() or PDOStatement::errorInfo() method on that object. If the error resulted from a call on the database object, you would invoke those methods on the database object instead.


In addition to setting the error code, PDO will emit a traditional E_WARNING message. This setting is useful during debugging/testing, if you just want to see what problems occurred without interrupting the flow of the application.


In addition to setting the error code, PDO will throw a PDOException and set its properties to reflect the error code and error information. This setting is also useful during debugging, as it will effectively "blow up" the script at the point of the error, very quickly pointing a finger at potential problem areas in your code (remember: transactions are automatically rolled back if the exception causes the script to terminate).

Exception mode is also useful because you can structure your error handling more clearly than with traditional PHP-style warnings, and with less code/nesting than by running in silent mode and explicitly checking the return value of each database call.

See Exceptions for more information about Exceptions in PHP.

PDO standardizes on using SQL-92 SQLSTATE error code strings; individual PDO drivers are responsible for mapping their native codes to the appropriate SQLSTATE codes. The PDO::errorCode() method returns a single SQLSTATE code. If you need more specific information about an error, PDO also offers an PDO::errorInfo() method which returns an array containing the SQLSTATE code, the driver specific error code and driver specific error string.

Example #1 Create a PDO instance and set the error mode

1 0 share
Enter your answer below

Anonymous Mode: No Yes

Discover New People * People You May Like To Follow

Question You May Like to Answer

Question Added . Information technology
Is the Facebook founder, Mark Zuckerberg smarter than Bill Gates, the founder of Microsoft
Add answer 2 answers -
Answer added . Webmaster
How much does Nigerian bloggers earn?
Answered by Anonymous 5 days ago

Many Nigerians have turned to blogging as a means to earn decent money online. Today, Nigerians are the most successful bloggers in Africa. There are d...... (More)
Add your answer
Post created . Education
Start your home lesson business
Published 13 May

Open in Link Ask Question

Question You May Like to Answer

Question Added . Entertainments
Is Davido in the Illuminati?
Add answer 3 answers -
Answer added . Webmaster
What is the differnce between Free DNS and Premium DNS?
Answered by Kubra Atikah 2 days ago

DNS (Domain Name Server) provides websites with additional benefits such as security measures, guaranteed speed and redundancy. Most domain registrars p...... (More)
Add your answer
Answer added . Webmaster
Why PHP in PDO?
Answered by obicheozo emeka 4 months ago
Studied Computer Science at Imo State University Owerri . Interested in Artificial Intelligent, Mobile Applications, Sports and Politics

PHP Data Object (PDO) is more secure than the normal PHP in MYSQL and MYSQLi. there are lots of security measures in PDO prepared statement and many mor...... (More)
Add your answer