Пример #1
0
        }
        if (preg_match('/^by_(?<column>[a-z_]+)$/', $name, $matches)) {
            $model_class = get_called_class();
            $table = self::table_name();
            $stmt = self::$pdo->prepare("SELECT * FROM `{$table}` WHERE {$matches['column']} = ?");
            $stmt->execute(array($arguments[0]));
            $objects = array();
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
                $objects[] = new $model_class($row);
            }
            return $objects;
        }
    }
    public static function connect()
    {
        global $config;
        try {
            self::$pdo = new PDO($config["db"]["dsn"], $config["db"]["user"], $config["db"]["pass"]);
        } catch (PDOException $e) {
            ?>
			<h1>Database connection failure</h1>
			<p>
				Please ensure the database settings in config.php are correct.
			</p>
			<?php 
            exit;
        }
    }
}
ModelBase::connect();