[PHP] php connects to mysql

<?php
class db{
//$res = mysqli_connect('localhost','root','root','bbb');
//public $connect='连接成功';
//public $sql="select user.user_name,user.pass,U_information.phonenumber,U_information.address from user inner join U_information";
//public function connect($res,$sql,$connect){
public function connect($res){
if($res){
//$res = mysqli_connect('localhost','root','root','bbb');
$sql="select user.user_name,user.pass,U_information.phonenumber,U_information.address from user inner join U_information";
$connect='连接成功';
echo $connect;
$bb=mysqli_query($res,$sql); echo '<hr/>'; echo 'The field information in the table is:';
$arr=mysqli_fetch_assoc($bb);



var_dump($arr);
echo '<hr/>';
echo 'The detailed information of each field of the table is:';
while($arr=mysqli_fetch_assoc($bb)){
echo '<hr/>';
var_dump( $arr);
}
}
else{
echo 'Connection failed, please try again! ';
}
}
}
$obj=new db;
$res = mysqli_connect('localhost','root','root','bbb');
//$sql="select user.user_name,user.pass,U_information. phonenumber,U_information.address from user inner join U_information";
//$connect='connection successful';
//$obj->connect($res,$sql,$connect);

$obj->connect($res);

Attached screenshot:


Related Posts