3 * @author Jan Altensen (Stricted)
4 * @copyright 2013-2014 Jan Altensen (Stricted)
5 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
10 private $error = NULL;
13 * Connects to SQL Server
17 public function connect($driver, $host, $user, $pass, $db, $port = Null) {
18 if (!extension_loaded("pdo")) die("Missing <a href=\"http://www.php.net/manual/en/book.pdo.php\">PDO</a> PHP extension."); // check if extension loaded
20 switch (strtolower($driver)) {
22 if (!extension_loaded("pdo_mysql")) die("Missing <a href=\"http://php.net/manual/de/ref.pdo-mysql.php\">pdo_mysql</a> PHP extension."); // check if extension loaded
23 if(empty($port)) $port=3306;
24 $this->conn
= new PDO("mysql:host=".$host.";port=".$port.";dbname=".$db, $user, $pass);
28 if (!extension_loaded("pdo_pgsql")) die("Missing <a href=\"http://php.net/manual/de/ref.pdo-pgsql.php\">pdo_pgsql</a> PHP extension."); // check if extension loaded
29 if(empty($port)) $port=5432;
30 $this->conn
= new PDO("pgsql:host=".$host.";port=".$port.";dbname=".$db, $user, $pass);
34 if (!extension_loaded("pdo_sqlite")) die("Missing <a href=\"http://php.net/manual/de/ref.pdo-sqlite.php\">pdo_sqlite</a> PHP extension."); // check if extension loaded
35 if(!file_exists($db)) {
38 if(file_exists($db) && is_readable($db) && is_writable($db)) {
39 $this->conn
= new PDO("sqlite:".$db, $user, $pass);
41 $this->error
= "cant crate/connect the/to sqlite database";
47 $this->error
= "not supported database type found";
52 } catch (PDOException
$e) {
53 $this->error
= $e->getMessage();
59 * close the database connection
61 public function close () {
66 * Sends a database query to SQL server.
68 * @param string $res a database query
70 * @return integer id of the query result
72 public function query ($res, $bind = array()) {
75 $query = $this->conn
->prepare($res);
76 if(is_array($bind) && !empty($bind))
77 $query->execute($bind);
81 } catch (PDOException
$e) {
82 $this->error
= $e->getMessage();
88 * Gets a row from SQL database query result.
90 * @param string $res a database query
91 * @return array a row from result
93 public function fetch_array ($res) {
95 return $res->fetch(PDO
::FETCH_ASSOC
);
96 } catch (PDOException
$e) {
97 $this->error
= $e->getMessage();
102 * return the last insert id
104 public function last_id () {
105 return $this->conn
->lastInsertId();
109 * Returns SQL error number for last error.
111 * @return integer MySQL error number
113 public function error () {