/ Published in: PHP
Abstract class from which other classes can be derived to handle database access and data retrieval.
Constants for database connection (DB_DSN, DB_USERNAME, etc.) must be set in another php file (eg. config.php)
Constants for database connection (DB_DSN, DB_USERNAME, etc.) must be set in another php file (eg. config.php)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
abstract class DataObject { public function __construct( $data ) { foreach ( $data as $key => $value ) { $this->data[$key] = $value; } } public function getValue( $field ) { return $this->data[$field]; else } public function getValueEncoded( $field ) { } protected function connect() { try { $conn = new PDO( DB_DSN, DB_USERNAME, DB_PWD ); $conn->setAttribute( PDO::ATTR_PERSISTENT, TRUE ); $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); } catch ( PDOException $e) { } return $conn; } protected function disconnect( $conn ) { $conn = NULL; } }