Участник
Зарегистрирован: Feb 2002
Место проживания: Ukraine
Публикаций: 2
Статус:  |
Я например пользуюсь вот этим классом всегда, если нужно дописываю в него функции.
PHP:
<?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 ))
Сообщить модератору об этом сообщении | Предупреждение | IP: определен
|