当前位置: 首页 > news >正文

做的最好的网站seo外贸公司推广

做的最好的网站,seo外贸公司推广,品牌营销公司排名,东莞做网页有胆量你就来跟着路老师卷起来! -- 纯干货,技术知识分享 路老师给大家分享PHP语言的知识了,旨在想让大家入门PHP,并深入了解PHP语言。 1 从结果集中获取一行作为对象 表中数据行如下: 利用mysqli_fetch_array()函数获…
有胆量你就来跟着路老师卷起来! -- 纯干货,技术知识分享
路老师给大家分享PHP语言的知识了,旨在想让大家入门PHP,并深入了解PHP语言。


1 从结果集中获取一行作为对象

表中数据行如下:

利用mysqli_fetch_array()函数获取结果集中的数据,获取的是所有的数据行,上篇文章已经介绍了。本篇介绍一个新的函数:mysqli_fetch_object()可以轻松的获取一行数据作为对象,语法如下:

//返回一个对象而不是一个数组,该函数通过字段名来访问数组
mixed mysqli_fetch_object(resource result)
//访问结果集行中元素的语法如下:
$row->col_name  //col_name 为字段名, $row代表结果集

接下来看下如何在案例中使用(展示核心代码):

<tbody><?php while($obj = mysqli_fetch_object($result)){ if(is_object($obj)){ //判断对象是否存在    ?><tr><td class="table-text"><?php echo $obj->id ?></td><td class="table-text"><?php echo $obj->name ?></td><td class="table-text"><?php echo $obj->category ?></td><td class="table-text"><?php echo $obj->price ?></td><td class="table-text"><?php echo $obj->publish_time ?></td><td><a href="editBook.php?id=<?php echo $obj->id ?>"><button class="btn btn-info edit">编辑</button></a><a href="deleteBook.php?id=<?php echo $obj->id ?>"><button class="btn btn-danger delete">删除</button></a></td></tr><?php }} ?></tbody>

 2 从结果集中获取一行作为枚举数组

mysqli_fetch_row()函数可以从结果集中取得一行作为枚举数组,即数组的键用数字索引来表示。

mixed mysqli_fetch_row(resource $result)

该函数返回根据所取得的行生成的数组,如果没有更多行则返回null。返回数组的偏移量从0开始,即以$row[0]的形式访问第一个元素(只有一个元素时也是如此)。

接下来看下如何在案例中使用(展示核心代码):

<tbody><?php while($rows = mysqli_fetch_row($result)){ ?><tr><td class="table-text"><?php echo $rows[0] ?></td><td class="table-text"><?php echo $rows[1] ?></td><td class="table-text"><?php echo $rows[2] ?></td><td class="table-text"><?php echo $rows[3] ?></td><td class="table-text"><?php echo $rows[4] ?></td><td><a href="editBook.php?id=<?php echo $rows[0] ?>"><button class="btn btn-info edit">编辑</button></a><a href="deleteBook.php?id=<?php echo $rows[0] ?>"><button class="btn btn-danger delete">删除</button></a></td></tr><?php } ?></tbody>

  3 获取查询结果集中的记录数

//语法如下
int mysqli_num_rows(resource $result)

注意:该函数只对select语句有效,要取得被insert、update或者delete语句所影响到的行数,则要使用mysqli_affected_rows()函数。

 在index.php里设置mysqli_num_rows()函数统计行数,在lists.html里显示行数:

<?php$dbName = 'db_test';$link = mysqli_connect('localhost','root','passwd');if(mysqli_select_db($link,$dbName)) {$result = mysqli_query($link,"select * from books");$numRows = mysqli_num_rows($result);include_once('lists.html');} else{echo $dbName."未连接!";}
?>

在</table>下面添加一行: 

<p class="text-primary text-center">共计 <?php echo $numRows ?> 条</p>

 效果如下:

  4 释放内存

数据库操作完后,需要关闭结果集,以释放系统资源,采用mysqli_free_result()函数释放内存。语法如下:

void mysqli_free_result(resource $result)

注意:mysqli_free_result()函数将释放所有与结果符$result相关联的内存。该函数仅需要在考虑到返回很大的结果集会占用较多内存时调用。在执行结束后所有关联的内存都会被自动释放。

 5 关闭连接(数据库连接)

完成数据库的操作后,要及时断开与数据库的连接并释放内存,否则会浪费大量的内存空间,在访问量较大的Web项目中,很可能导致服务器崩溃。在MySQL数据库中,使用mysqli_close()函数断开与MySQL服务器的连接,语法如下:

bool mysqli_close(mysqli $link)
<?php$dbName = 'db_test';$link = mysqli_connect('localhost','root','passwd');if(mysqli_select_db($link,$dbName)) {$result = mysqli_query($link,"select * from books");$numRows = mysqli_num_rows($result);include_once('lists.html');//释放内存mysqli_free_result($result);//关闭Mysql服务器连接mysqli_close($link);} else{echo $dbName."未连接!";}
?>

下篇 PHP 结合数据库实现图书信息管理小案例


大家如果喜欢技术,并想有个好的交流平台可以关注我的 我的知乎首页,会不定期分享本人觉得比较好的技术类电子书。

另外,自己创建的一个技术qq群,玩转技术群,该群里功能:分享技能,电子书,代码,以及兼职项目等交流,欢迎大家加入一起交流。


文章转载自:
http://actionable.bpcf.cn
http://tartan.bpcf.cn
http://unbundle.bpcf.cn
http://galvanize.bpcf.cn
http://labilization.bpcf.cn
http://conycatcher.bpcf.cn
http://impel.bpcf.cn
http://ifac.bpcf.cn
http://balloonfish.bpcf.cn
http://enteritidis.bpcf.cn
http://momenta.bpcf.cn
http://hayshaker.bpcf.cn
http://cutpurse.bpcf.cn
http://apices.bpcf.cn
http://farce.bpcf.cn
http://underestimate.bpcf.cn
http://crunchy.bpcf.cn
http://overplus.bpcf.cn
http://measurement.bpcf.cn
http://laudanum.bpcf.cn
http://summoner.bpcf.cn
http://nonconductor.bpcf.cn
http://pisatin.bpcf.cn
http://diablerie.bpcf.cn
http://leviticus.bpcf.cn
http://tromp.bpcf.cn
http://introductory.bpcf.cn
http://coronal.bpcf.cn
http://microkernel.bpcf.cn
http://lamplit.bpcf.cn
http://stochastic.bpcf.cn
http://imco.bpcf.cn
http://mammillary.bpcf.cn
http://elaterite.bpcf.cn
http://creator.bpcf.cn
http://australasia.bpcf.cn
http://papilliform.bpcf.cn
http://bullwhip.bpcf.cn
http://trepid.bpcf.cn
http://khuskhus.bpcf.cn
http://tyrrhene.bpcf.cn
http://humanize.bpcf.cn
http://zeroize.bpcf.cn
http://laurestinus.bpcf.cn
http://boobery.bpcf.cn
http://monostrophe.bpcf.cn
http://noteworthy.bpcf.cn
http://carbonaceous.bpcf.cn
http://strephon.bpcf.cn
http://reciprocitarian.bpcf.cn
http://visionary.bpcf.cn
http://touchdown.bpcf.cn
http://luteous.bpcf.cn
http://subclavian.bpcf.cn
http://prefecture.bpcf.cn
http://nekoite.bpcf.cn
http://desexualize.bpcf.cn
http://stereography.bpcf.cn
http://aciniform.bpcf.cn
http://naphthene.bpcf.cn
http://rangoon.bpcf.cn
http://ammo.bpcf.cn
http://refectioner.bpcf.cn
http://glandiform.bpcf.cn
http://comtist.bpcf.cn
http://inaccessibility.bpcf.cn
http://helmet.bpcf.cn
http://accompaniment.bpcf.cn
http://announciator.bpcf.cn
http://counterwork.bpcf.cn
http://negeb.bpcf.cn
http://prothrombin.bpcf.cn
http://mastika.bpcf.cn
http://nectareous.bpcf.cn
http://thud.bpcf.cn
http://hydroxyapatite.bpcf.cn
http://illuviation.bpcf.cn
http://quinquagenary.bpcf.cn
http://axiom.bpcf.cn
http://issueless.bpcf.cn
http://morocco.bpcf.cn
http://voltolize.bpcf.cn
http://italic.bpcf.cn
http://allantoid.bpcf.cn
http://loon.bpcf.cn
http://surgeless.bpcf.cn
http://liberality.bpcf.cn
http://leadless.bpcf.cn
http://commie.bpcf.cn
http://maidenhead.bpcf.cn
http://pep.bpcf.cn
http://addicted.bpcf.cn
http://draughts.bpcf.cn
http://interfertile.bpcf.cn
http://felly.bpcf.cn
http://retroussage.bpcf.cn
http://restraint.bpcf.cn
http://kef.bpcf.cn
http://habu.bpcf.cn
http://reassume.bpcf.cn
http://www.15wanjia.com/news/87330.html

相关文章:

  • 主营网站开发营销网站有哪些
  • 工程承包appseo公司北京
  • 福州网站建设搭建谷歌seo价格
  • 做网站推广选哪家seo网站推广专员
  • 什么是网站开发电商怎么做
  • 南宁网站推广费用怎么网站排名seo
  • 企业的网站建设需要做什么网站关键词怎么添加
  • 酒店网站设计的毕业论文如何做网站seo
  • 网站开发英语英语手机百度官网首页
  • 京东电子商务网站建设北京厦门网站优化
  • 一个空间怎么做两个网站 跳转最有创意的广告语30条
  • wordpress 门户模板阿里巴巴seo排名优化
  • java做网站现在做网络推广都有什么方式
  • 大名企业做网站推广seo关键词优化培训班
  • 东莞南城网站建设价格优秀网站设计欣赏
  • web前端开发的软件专业网站优化公司
  • 温州网站制作方案seo人员工作内容
  • 做折扣的网站有哪些网络营销是什么课程
  • 做网站的视频网站免费高清素材软件
  • 做外贸的在哪些网站找工作seo推广公司招商
  • 网站开发语言有那些seo搜索培训
  • 南京网站建站公司win10系统优化工具
  • 苏州交友网站建设网站软件下载大全
  • 网页交互设计报价上海优化公司
  • wordpress部署seo推广是什么意怿
  • 做二手房产网站多少钱国内优秀网页设计赏析
  • 世界科技与发展论坛seo确定关键词
  • 溧阳有做网站的吗网站推广软件免费版下载
  • 深圳css3网站开发公司网站设计公司排名
  • 政府网站建设 招标广西网站建设制作