php和mysql交互 面向对象

不返回结果集

<?php //使用对象属性和方法来插入数据 header('Content-type:text/html;carset=utf8'); $con=new mysqli('localhost','root','123456','t3',3306); $str='insert into tech values (9,"刘海波",132789)'; if($con->connect_error){ $con->connect_error(); } $con->set_charset('utf8'); if($con->query($str)==true){ echo '插入数据成功'; }else{ echo 'ERRPR'.$str.$con->error; } $con->close(); ?>

 返回结果集

<?php
//使用对象属性和方法来插入数据
header('Content-type:text/html;carset=utf8');
$con=new mysqli('localhost','root','123456','t3',3306);
$str='select * from tech';
if($con->connect_error){
    $con->connect_error();
}
$con->set_charset('utf8');
$result=$con->query($str);
//fetch_assoc 返回数组
while($jieguo=$result->fetch_assoc()){

    echo $jieguo['id'].'-------'.$jieguo['name'].'---------'.$jieguo['pwd'].'--------'.'<br>';
}


$con->close();

?>

  

猜你喜欢

转载自www.cnblogs.com/xiaowie/p/11949197.html
今日推荐