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
Upvote
2
Downvote
0 0 4

Answered: Aigbe Marvellous 2 months ago

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

Upvote
1
Downvote
0 0 share
Answered: Jessie Priscilla 2 months ago

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

Upvote
0
Downvote
0 0 share
Answered: Marvellous Ebi 2 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

Upvote
4
Downvote
0 0 share
Answered: obicheozo emeka 2 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.


Conclusion
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.


PDO::ERRMODE_SILENT


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.


PDO::ERRMODE_WARNING


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.


PDO::ERRMODE_EXCEPTION


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


Upvote
1
Downvote
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 . Economics
What type of revenue allocation practiced in Nigeria?
Add answer 1 answer -