![]() |
Показаны 4 сообщений на этой странице |
Форум сетевых администраторов (http://netadmin.ws/forum/index.php)
- PHP (http://netadmin.ws/forum/forumdisplay.php?forumid=6)
-- Классы для работы с MySQL (http://netadmin.ws/forum/showthread.php?threadid=1007)
Классы для работы с MySQL
Кто какие хорошие классы для работы с MySQL знает?
__________________
Всегда есть решение.
Я например пользуюсь вот этим классом всегда, если нужно дописываю в него функции.
<?php
class MySQL {
var $host, $user, $password, $database, $connect_id, $result, $query;
function MySQL () {
$this->host = $sql_host;
$this->user = $sql_user;
$this->password =$sql_pwd;
$this->SetDB ($sql_database);
$this->Connect ();
}
function Connect () {
$this->connect_id = mysql_pconnect ($this->host, $this->user,
$this->password);
if ($this->connect_id):
$this->SelectDB ();
return $this->connect_id;
else:
die("Can't connect to MySQL");
return false;
endif;
}
function SelectDB () {
mysql_select_db($this->database, $this->connect_id);
}
function SetDB ($database) {
$this->database = $database;
}
function SetQuery ($query) {
$this->query = $query;
}
function ExecQuery($query) {
$this->SetQuery ($query);
$this->result = mysql_query ($this->query);
if ($this->result):
return $this->result;
else:
return false;
endif;
}
function Exec () {
$this->result = mysql_query ($this->query);
if ($this->result):
return $this->result;
else:
return false;
endif;
}
function NumRows () {
if ($this->result):
return mysql_num_rows($this->result);
else:
return false;
endif;
}
function UnsetData () {
mysql_free_result($this->result);
unset ($this->query);
unset ($this->result);
}
function Error () {
if (mysql_errno() != 0):
return mysql_errno().": ".mysql_error()."<br>\n";
else:
return false;
endif;
}
function FetchArray () {
if ($this->result != 0):
return mysql_fetch_array($this->result);
else:
echo $this->Error ();
return false;
endif;
}
function FetchRow () {
if ($this->result != 0):
return mysql_fetch_row($this->result);
else:
echo $this->Error ();
return false;
endif;
}
function FieldArray($table)
{
global $sql_database;
$fields=mysql_list_fields($sql_database,$table);
$columns = mysql_num_fields($fields);
for ($i = 0; $i < $columns; $i++)
{
$fieldname_arr[$i]=mysql_field_name($fields, $i);
$fieldtype_arr[$i]=mysql_field_type($fields,$i);
}
$field_arr[0]=$fieldname_arr;
$field_arr[1]=$fieldtype_arr;
return $field_arr;
}
function FetchObject() {
if ($this->result != 0):
return mysql_fetch_object($this->result);
else:
echo $this->Error ();
return false;
endif;
}
function IsTableExist($table)
{
global $sql_database;
$result = mysql_list_tables ($sql_database);
for ($i=0;$i < mysql_num_rows($result);$i++)
{
$tb_name = mysql_tablename ($result, $i);
if ($table==$tb_name) return true;
}
return false;
}
}
?>
))
__________________
comming soon
))
имхо, в библиотеке PEAR неплохие классы для работы со всеми поддерживаемыми базами данных.
__________________
С уважением, Dm
Да классов куча, хотелось бы найти такой класс который автоматом разбивал бы данные и при добавлении их в базу добавля бы слэши и наооборот убирал бы их при получении, при этом чтобы не терялся синтаксис SQL. Кстати возможно ли включить magic_quotes_runtime в функции которая добавляет данные в базу, и дало бы это должный эффект?
__________________
Всегда есть решение.
| Формат времени GMT. Текущее время 12:21. | Показаны 4 сообщений на этой странице |
Powered by: vBulletin Version 2.2.4
Copyright © Jelsoft Enterprises Limited 2000, 2001.