每日总结

1.php连接数据库练习

$link=mysqli_connect("localhost","root","123456");
//判断连接成功
if(!$link)
{
echo '连接失败';
//return;
}
//选择数据库
mysqli_select_db($link,"goodlist");
//设置字符集
mysqli_set_charset($link,'utf8');
//准备sql语句
$sql="select * from goodtype";
//发送sql语句
$result=mysqli_query($link,$sql);
//处理数据
if($result)
{
//fetch_row获取行的数据
//mysqli_detch_assoc获取对应键值,$attr['linenum']可获取数据
//获取字段数
//echo mysqli_num_fields($result),"<br/>";
//获取信息数
//echo mysqli_num_rows($result),"<br/>";
while($attr=mysqli_fetch_array($result))
{
?>
<option value="<?php echo $attr[0]; ?>"><?php echo $attr[1]; ?></option>
<?php
}


}
//关闭数据库连接
mysqli_close($link);
原文地址:https://www.cnblogs.com/chenghaixiang/p/14914274.html