PHP MYSQLI扩展库面向对象编程 数据库连接 例子
<?php Header("Content-Type:text/html;charset=utf-8"); $mysqli = new mysqli("localhost","root","xxx","test"); if($mysqli->connect_error){ die("数据库连接错误<br />".$mysqli->connect_error); } $sql = "select * from user1"; $mysqli->query("SET NAMES utf8"); $mysqli_result = $mysqli->query($sql) or die("SQL语句问题<BR />".$mysqli->error); while($row=$mysqli_result->fetch_row()){ foreach($row as $key=>$val){ echo "-$val"; } echo "<br />"; } $mysqli_result->free(); $mysqli->close(); ?>