50 lines
No EOL
1.1 KiB
PHP
50 lines
No EOL
1.1 KiB
PHP
<?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();
|
||
}
|
||
}
|
||
|
||
?>
|