phplibrary/core/drivers/database.mysql.php
2016-07-14 16:29:26 +03:00

50 lines
No EOL
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once 'core/drivers/db.php';
/**
* Простой класс для работы с базами данных
*/
class Database_MYSQL extends DB implements IDatabase
{
public function connect(array $dsn)
{
$db = @mysql_pconnect($dsn['hostspec'], $dsn['username'], $dsn['password'])
or die("Unable connect to database!");
mysql_select_db($dsn['database']);
return ($this->db = $db);
}
public function close()
{
return mysql_close($this->db);
}
public function query($query)
{
$res = mysql_query($this->db, $query)
or die("Error: wrong SQL query #$query#");
return $res;
}
public function fetchAllArray($query)
{
$res = $this->query($query);
while ($row = mysql_fetch_array ($res))
$rows[] = $row;
mysql_free_result($res);
return ($rows) ? $rows : array();
}
public function fetchOneArray($query)
{
$res = $this->query($query);
$row = mysql_fetch_array($res);
mysql_free_result($res);
return ($row) ? $row : array();
}
}
?>