apysan Posted May 8, 2015 Share Posted May 8, 2015 Hello friends, I have just begun to learn PHP. I prefer to learn in PDO way. I write the following code to connect to phpmyadmin (wamp). unable to understand the use of this function, even if it is useful why do we mention only two parameter with this, please help to understand. try{ $handler = new PDO('mysql:host=localhost;dbname=arjun_kaa_database','root',''); $handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { //echo "An Error is Catched<br>"; //$e->getmessage(); //die("More Specific Message will be >--------------> Something Wrong with the Database"); echo $e->getMessage(); die(); } Thanks and Regards Link to comment Share on other sites More sharing options...
Ingolme Posted May 8, 2015 Share Posted May 8, 2015 What that line is doing is telling PDO to throw an exception if a MySQL error occurrs. This would mean you can catch MySQL errors using a try-catch block. For example: try { // .. Some PDO database operations} catch(PDOException $e) { echo 'MySQL error: ' . $e->getMessage();} PDO's setAttribute() method just sets some of PDO's configuration. 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted May 11, 2015 Share Posted May 11, 2015 The manual lists some of the attributes that you can set:http://php.net/manual/en/pdo.setattribute.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now