What does this mean in PDO?

Source: Internet
Author: User
What does this mean in PDO? This horizontal bar $ pdo-> and two colons PDO: What does it mean?
Do you want to write errors like this? where can I write other code?

Try {
$ Pdo = new PDO ('MySQL: host = localhost; dbname = t2', 'root ','');
$ Pdo-> setAttribute (PDO: ATTR_ERRMODE, PDO: ERRMODE_EXCEPTION );
}
Catch (PDOException $ e ){
Echo "database connection failed:". $ e-> getMessage ();
Exit;
}

?>


Reply to discussion (solution)

Static variables of PDO

Static variables of PDO

PDO: Call the static property of the PDO class.

-> Here, it indicates the properties and methods of the called object.

Let's take a look at the php object section below.

First, popularize the basic knowledge:
->Indicates the object member (attributes and methods)
::Represents the static members (attributes and methods) of a class)

PDO has two error handling methods:
1. in the traditional method, check the returned value of the errorCode method to determine whether an error has occurred. The errorInfo method returns the complete error message.
2. exception throw method. In your example

As an exception, new PDO supports both methods, that is
New PDO (.....);
And
Try {
New PDO (.....);
} Catch (PDOException $ e ){
Echo $ e-> getMessage ();
}
The results are the same.

Where can I write other code when exception handling is used?
The answer is: in the try branch
Any statement that has a problem will go to the catch branch.

Object instance
Static Member variable attributes

In short, the constants defined in the PDO class are generally capitalized.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.