Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Description of dbClass
- *
- * @author fabi0
- */
- final class dbClass {
- private static $databaseInstance = NULL;
- private function __construct() {
- }
- public static function query($sql, $params = array()) {
- $return = array();
- if (!is_object(self::$databaseInstance)) {
- self::setInstance();
- }
- $sth = self::$databaseInstance->prepare($sql);
- foreach ($params as $key => $value) {
- $sth->bindParam(':' . $key, $value);
- }
- $sth->execute();
- while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
- $return[] = $result;
- }
- return $return;
- }
- private function setInstance() {
- if (!is_object(self::$databaseInstance)) {
- self::$databaseInstance = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASSWORD);
- self::$databaseInstance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- }
- public static function getInstance() {
- return self::$databaseInstance;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement