01.
class
DB {
02.
public
$cnx
;
03.
public
$result
;
04.
public
function
__construct(
$host
,
$user
,
$psw
,
$dbname
) {
05.
$this
->cnx =
new
mysqli(
$host
,
$user
,
$psw
,
$dbname
);
06.
if
(
$this
->cnx->errno) {
07.
die
(
'Connection failed! '
.
$this
->cnx->error);
08.
}
else
{
09.
echo
"connected"
;
10.
}
11.
return
true;
12.
}
13.
public
function
arr() {
14.
$result
=
$this
->cnx->query(
"SELECT * FROM users"
)) {
15.
}
16.
}
17.
$db
=
new
DB(
'host'
,
'user'
,
'psw'
,
'dbname'
);
18.
$db
->arr();
19.
if
(
$db
->result){
20.
echo
'row is '
.
$db
->result->num_rows();
21.
}
else
{
22.
echo
$db
->cnx->error;
23.
}