01.
<?php
02.
error_reporting
(E_ALL);
03.
class
_MySql
04.
{
05.
06.
private
$ihost
;
07.
private
$iuser
;
08.
private
$ipass
;
09.
private
$idb_name
;
10.
private
$ilink
;
11.
12.
13.
private
$_res
;
14.
15.
16.
private
$_fetch_array
=
array
();
17.
18.
public
function
_ConnectSQL (
$ihost
,
$iuser
,
$ipass
,
$idb_name
)
19.
{
20.
$this
->ihost =
$ihost
;
21.
$this
->iuser =
$iuser
;
22.
$this
->ipass =
$ipass
;
23.
$this
->idb_name =
$idb_name
;
24.
25.
$this
->ilink = mysql_connect(
$this
->ihost ,
$this
->iuser ,
$this
->ipass );
26.
mysql_query (
"SET NAMES UTF8"
);
27.
mysql_query(
"SET character_set_results=utf8"
);
28.
mysql_query(
"SET character_set_client=utf8"
);
29.
mysql_query(
"SET character_set_connection=utf8"
);
30.
mysql_select_db(
$idb_name
,
$this
->ilink );
31.
32.
33.
}
34.
35.
public
function
_QuerySQL (
$strrs
)
36.
{
37.
return
$this
->_res = mysql_query(
$strrs
);
38.
}
39.
40.
public
function
_Num_Rows_SQL ()
41.
{
42.
return
mysql_num_rows(
$this
->_res);
43.
}
44.
45.
public
function
_Fetch_Array_SQL()
46.
{
47.
if
(
count
(
$this
->_fetch_array ) > 0 )
48.
{
49.
return
$this
->_fetch_array;
50.
}
51.
else
52.
{
53.
while
(
$row
= mysql_fetch_array(
$this
->_res) )
54.
{
55.
$this
->_fetch_array[] =
$row
;
56.
}
57.
58.
return
$this
->_fetch_array;
59.
}
60.
61.
62.
}
63.
64.
public
function
_CloseSQL()
65.
{
66.
return
mysql_close(
$this
->ilink);
67.
}
68.
69.
}
70.
71.
$obj
=
new
_MySql();
72.
$obj
->_ConnectSQL(
'localhost'
,
'root'
,
''
,
'project1'
);
73.
$obj
->_QuerySQL(
"select * from member"
)
or
die
(mysql_error());
74.
echo
$obj
->_Num_Rows_SQL()
or
die
(mysql_error());
75.
print_r (
$obj
->_Fetch_Array_SQL())
or
die
(mysql_error());
76.
$obj
->_CloseSQL()
or
die
(mysql_error());
77.
?>