今天本来要实现利用smarty实现分页,但是由于要连接数据库的原因,今天还是着重讲解了mysqli的知识点。
成功连接数据库的例子:
<?php
$mysqli = new mysqli("localhost","root","","product");
//$mysqli->more_results();
//$mysqli->next_result();
$sql="set names utf8;select * from product;select * from product";
if($mysqli->multi_query($sql)){
do{
if($result = $mysqli->store_result()){
while($row = $result->fetch_row()){
foreach($row as $value){
echo $value."<br>";
}
}
echo "<br>";
echo $result->num_rows."行";//成员属性
echo "<br>";
echo $result->field_count."列";
echo "<br>";
echo $result->current_field."当前列";
echo "<br>";
$result->field_seek(1);
echo $result->current_field."当前列";
echo "<br>";
$a = $result->fetch_field();
echo "第二个字段名称".$a->name ;
echo "<br>";
$b = $result->fetch_field();
echo "第三个字段名称".$b->name ;
echo "<br>";
}
}while($mysqli->next_result());
}
?>
实现的效果:
1
name1
1.02
good1
2
name2
1.02
good2
2行
4列
0当前列
1当前列
第二个字段名称name
第三个字段名称price
1
name1
1.02
good1
2
name2
1.02
good2
2行
4列
0当前列
1当前列
第二个字段名称name
第三个字段名称price
此效果居委从数据库中获取到的信息。