note 114791 added to pdo.construct
| From: | Anonymous | Date: | Mon, 07 Apr 2014 13:55:15 +0000 |
| Subject: | note 114791 added to pdo.construct | ||
| Groups: | php.notes php.notes | ||
| Request: | Send a blank email to php-notes+get-199206@lists.php.net to get a copy of this message | ||
To connect to the database via a function use this and call the getConnection function in the class
constructor.
<?php
class Connection{
protected $db;
public function Connection(){
$conn = NULL;
try{
$conn = new PDO("mysql:host=localhost;dbname=dbname", "dbuser",
"dbpass");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
echo 'ERROR: ' . $e->getMessage();
}
$this->db = $conn;
}
public function getConnection(){
return $this->db;
}
}
?>
----
Server IP: 83.137.20.135
Probable Submitter: 62.45.102.204
----
Manual Page -- http://php.net/manual/en/pdo.construct.php
Edit -- https://master.php.net/note/edit/114791
Del: integrated -- https://master.php.net/note/delete/114791/integrated
Del: useless -- https://master.php.net/note/delete/114791/useless
Del: bad code -- https://master.php.net/note/delete/114791/bad+code
Del: spam -- https://master.php.net/note/delete/114791/spam
Del: non-english -- https://master.php.net/note/delete/114791/non-english
Del: in docs -- https://master.php.net/note/delete/114791/in+docs
Del: other reasons-- https://master.php.net/note/delete/114791
Reject -- https://master.php.net/note/reject/114791
Search -- https://master.php.net/manage/user-notes.php