PHP Code:
<?php
try
{
return new PDO("mysql:dbname=cpanel_username_db_name;host=localhost","cpanel_username_db_user","pw_here");
}
catch(PDOException $error) // $error returns error from PDOException class
{
echo "<p><b>Database connection error.</b></p>";
echo "<p>".$error->getMessage()."</p>";
die();
}
?>
As you can see on the PDO class constructor page:
PDO::__construct() throws a PDOException if the attempt to connect to the requested database fails.
What is "instantiation"?
Instantiation (or creating an instance of) is the term to describe creating an instance of a class to use the functionality within a class. A class is merely a container until you create an instance of it in memory. Kind of like an installed application on your computer that is not being run. See: http://forums.eukhost.com/f50/object...ple-php-16963/
What is the "class constructor"?
The class constructor is like an ordinary method (or class "function") that is executed as soon as the class is instantiated. Essentially, it is a method of the class itself. For example, if you had a method called connect(), you would need to creating an instance of the class that method is part of, and then execute the method with that new instance. For example:
PHP Code:
<?php
$instance = new Class();
$instance->connect(); // connect() method of the class called "Class"
?>