54 lines
No EOL
1.3 KiB
PHP
54 lines
No EOL
1.3 KiB
PHP
<?php
|
|
|
|
require_once 'core/drivers/db.php';
|
|
|
|
/**
|
|
* Ïðîñòîé êëàññ äëÿ ðàáîòû ñ áàçàìè äàííûõ
|
|
*/
|
|
class Database_ODBC extends DB implements IDatabase
|
|
{
|
|
public function connect(array $dsn)
|
|
{
|
|
$db = @odbc_connect($dsn['database'], $dsn['username'], $dsn['password'])
|
|
or die("Unable connect to database!");
|
|
return ($this->db = $db);
|
|
}
|
|
|
|
public function close()
|
|
{
|
|
return odbc_close($this->db);
|
|
}
|
|
|
|
public function query($query)
|
|
{
|
|
$res = odbc_exec($this->db, $query)
|
|
or die("Error: wrong SQL query #$query#");
|
|
return $res;
|
|
}
|
|
|
|
public function fetchAllArray($query)
|
|
{
|
|
$res = $this->query($query);
|
|
$to = odbc_num_fields($res);
|
|
while (odbc_fetch_row($res)) {
|
|
for ($i = 1; $i <= $to; $i++) {
|
|
$row [odbc_field_name($res, $i)] = trim(odbc_result($res, $i));
|
|
}
|
|
$rows[] = $row;
|
|
}
|
|
return ($rows)? $rows : array();
|
|
}
|
|
|
|
public function fetchOneArray($query)
|
|
{
|
|
$res = $this->query($query);
|
|
if (!odbc_fetch_row($res)) return array ();
|
|
$to = odbc_num_fields($res);
|
|
for ($i = 1; $i <= $to; $i++) {
|
|
$row [odbc_field_name($res, $i)] = trim(odbc_result($res, $i));
|
|
}
|
|
return $row;
|
|
}
|
|
}
|
|
|
|
?>
|