Error message displaying after execution of a query
We can display error message in case of an error generated by mysql query. This meaning full error message gives idea one the problem or bugs in the script. We can print the error message by using mysql function mysql_error(). This function returns the error message associated with most recently executed query. So it is a good idea to check for error before going to next query. We can even add the error number returned by mysql to this error message. This way we can generate a meaningful detail on the bugs on the script.
So to get correct result change the sql part like this .
$pdo=$dbo->prepare('Select * from student');
With this you will get desired output.
Handling PDO errors
If such error occurs what is to be done ? We have three options to handle in case of errors.
We can stop the execution of the script. ( Fatal error : stop execution of code )
We can display warning message ( Warning only, display message and no stoppage of execution )
Remain silent ( continue to execute and display error message if required )
Setting the PDO error handling attribute.
We can use setAttribute to tell how to handle the PDO errors.
Here is a sample
$dbo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); // gives warning only