作者:信妹氵V | 来源:互联网 | 2023-05-18 19:08
$mysqli = new mysqli("localhost", "数据库用户名", "数据库密码", "数据库名称");
/*
* This is the "official" OO way to do it,
* BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
*/
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
$mysqli->query("SET NAMES 'utf8'");
$result = $mysqli->query("SELECT * FROM 数据表 LIMIT 10");
/* Select queries return a resultset */
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo $row["title"];
/* free result set */
$result->close();
}
$mysqli->close();
php
header('Content-Type:text/html;Charset=utf-8');
$db = new mysqli();
$db->connect('localhost','root',19730123,'test');
$db->set_charset('utf8');
$sql='select * from pw_luck';
$query=$db->query($sql);
echo '';
while($rs=mysqli_fetch_array($query)){
$result[]=$rs;
}
$i=0;
print_r($result);
echo '
';
foreach($result as $key=>$value){
//if($i%2==0){
echo $key.'<->'.$value[0].'<->'.$value[1].'<->'.$value[2].'<->'.$value[3].'
';
//}
$i+=1;
}
$query->free();
$db->close();