php class Mysql function __construct dblocation localhost dbname dbuse

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class Mysql
{
function __construct()
{
$dblocation='localhost';
$dbname='';
$dbuser='';
$dbpasswd='';
$this->dbcnx=mysql_connect($dblocation,$dbuser,$dbpasswd);
mysql_select_db($dbname,$this->dbcnx);
mysql_unbuffered_query("SET `character_set_client` = 'utf8';");
mysql_unbuffered_query("SET `character_set_results` = 'utf8';");
mysql_unbuffered_query("SET `collation_connection` = 'utf8_general_ci';");
}
function connect()
{
if (!$this->dbcnx)
return 0;
else return 1;
}
static $num;
static $log=array();
function qw($q)
{
Mysql::$log[]=$q;
if (!$q=mysql_query($q))
{
//die('ошибка бд');
die(mysql_error());
}
Mysql::$num++;
return $q;
}
function value($q)
{
if (mysql_num_rows($res=Mysql::qw($q))!=1)
return 0;
return mysql_result($res,0,0);
}
}