Blogger Information
Blog 24
fans 1
comment 0
visits 20847
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
mysqli类对象链接数据库并显示出结果集
知行合一
Original
772 people have browsed it
  1. //1.建立到Mysql的链接
  2. $mysqli= new mysqli('127.0.0.1','root','123456','zl.com');
  3. //无法链接时,输出错误信息
  4. if($mysqli->connect_errno){
  5. die("CONNECT_ERROR:".$mysqli->connect_error);
  6. }
  7. //2.设置默认的客户端字符集
  8. $mysqli->set_charset('utf-8');
  9. //3.查询数据
  10. //通过mysqli->query成功执行select,show,describe或explain查询会返回一个mysqli_result对象,其它查询返回True。失败返回False.
  11. $sql= "select `title`,`url` from ey_links";
  12. $res=$mysqli->query($sql);
  13. //mysqli_result:fetch_all抓去所有的结果并且以关联数组MYSQLI_ASSOC,数值索引数组MYSQLI_NUM,或者两者皆有MYSQLI_BOTH的方式返回结果集
  14. $a=$res->fetch_all();//默认是MYSQLI_NUM
  15. print_r($a);

下面是数据表信息

下面是遍历出来的结果集

总结

难度不大,都是一些要记忆性的知识点。多做几次,不要看案例,自己来写。写错了,再看案例,这样记忆深刻。
如果只看不练,自己实操起来是啥都不会!

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:编程就是学游泳, 看上去会了, 下水就淹死, 编程也是一样, 一定要动手
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post