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>