mysqli常用属性方法

mysqli常用属性方法
mysqli有三个类

mysqli和连接有关的类
mysqli_result表达了对数据库的查询所返回的结果集
mysql_stmt()预处理类
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
 
<body>
<?php
$mysqli=new mysqli("localhost","root","root","test");
 
$sql="select *From shops";
$res=$mysqli->query($sql);
 
$row=$res->num_rows;
$cols=$res->field_count;
echo "表中有{$row}行,{$cols}列<br/>";
//记录信息
         /*  $result->fetch_row()  ----  mysql_fetch_row()      索引数组
          *  $result->fetch_assoc() ---  mysql_fetch_assoc()    关联数组(下标就是列名)
          *  $result->fetch_array()  ---- mysql_fetch_array()   两个数组都返回(MYSQLI_ASSOC, MYSQLI_NUM,MYSQLI_BOTH(default))
          *  $result->fetch_object()  --- mysql_fetch_object() 
          * 
          *  每次执行一次,就会从结果集中取出当前一条记录(当前记录就是第一个行,可以使用data_seek(5))
          *    
          *   指针指向下一行,下次再取时,就会取出下一行,当结果集中没有记录时,则返回false     
          *
          */
//$rows=$res->fetch_assoc();
//print_r($rows);
echo '<table border="1" align="center" width="900">';
 
echo '<tr>';
while($fieid=$res->fetch_field()){
         echo '<th>'.$fieid->name.'</th>';
}
echo '</tr>';
        
while($rows=$res->fetch_assoc()){        
//$res->data_seek(10);
         echo '<tr>';
         foreach($rows as $key){
                   echo '<td>'.$key.'</td>';
                   }
         echo '<tr/>';
         }
echo '</table>';
$res->close();
$mysqli->close();
?>
</body>
</html>
 
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
mysqli=new mysqli("localhost","root","root","test");
/*$sqls="insert into shops(name,price,num,desn)values('phpabc',89,1000,'php is hello');update shops set name='phpdef' where id=27;delete from shops where id=26";*/
$sqls="select *from shops;";
$sqls.="desc products;";
$sqls.="select now();";
if($mysqli->multi_query($sqls)){
         echo '多条语句执行成功';
//      echo '影响的行数'.$mysqli->affected_rows;
do{
$res=$mysqli->store_result();
echo '<table align="center" width="800" border="1">';
  echo '<tr>';
                while($field=$res->fetch_field()){
                            echo '<th>'.$field->name.'</th>';
                            }
  echo '<tr>';
 
  while($row=$res->fetch_assoc()){
           echo '<tr>';
                         foreach($row as $cols){
                                     echo '<td>'.$cols.'</td>';
                                     }
            echo '<tr>';
          
           }
         echo '</table>';
         echo '<br/>';
}
 while(
         $mysqli->next_result());
        
         }else{
         echo "ERROE:".$mysqli->error;
                   }
 
$mysqli->close();
?>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值