$con=mysqli_connect('localhost','root','root') 连接数据库 后面参数为账号和密码 连接成功返回mysql连接标识符 连接失败返回false
mysqli_select_db($con,'t1') 选择数据库 成功为true,失败为false
mysql_query("set names 'utf8'"); 设置使用的字符编码
mysqli_close($con) 关闭连接
mysqli_query($con,'set names utf8'); 设置为utf8编码格式
mysqli_query($con,'insert demo(username,age,password) values("ali","19","123321")') 插入内容
echo mysqli_error($con); 输入mysql错误信息
$query = mysqli_query($con,'select username,password from music');
while($row=mysqli_fetch_row($query)){ 获取返回的值 通过索引
printf ("%s (%s)
", $row[0], $row[1]);
}
$result=mysqli_query($con,'select * from music');
$row = mysqli_fetch_array($result); 可以通过索引和值 比如$row['username']
echo $row[0], $row['password'];
$result=mysqli_query($con,'select * from music');
$row = mysqli_fetch_array($result,MYSQLI_ASSOC); 通过值$row['username']
echo $row['username'], $row['password'];
$result=mysqli_query($con,'select * from music');
$row = mysqli_fetch_array($result,MYSQLI_NUM); 通过索引获取返回值
echo $row[0], $row[1];
$row = mysqli_fetch_assoc($result); 等同于 $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$result=mysqli_query($con,'select * from music');
$row = mysqli_num_rows($result); 取结果集的行数
print_r($row);
mysqli_affected_rows($con); 获取修改的数据数量