有人遇到mysqli的fetch_assoc()方法出错吗?
配置是phpnow5.1.6 :windowsXP + php5.2.14 + apache2.2.6 + MySQL5.1.50
在用mysqli类的fetch_assoc()时,Apache好像歇菜了。见如下代码:
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ -->while($row =$rs->fetch_assoc()) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "<td>" . $row['HomeTown'] . "</td>"; echo "<td>" . $row['Job'] . "</td>"; echo "</tr>"; }
IE提示无法显示页面,FF提示载入页面时到服务器的连接被重置。
如果把上面的代码去掉则恢复正常。
如果把fetch_assoc关联数组代换为fetch_row()的索引数组也没事,对应把$row['FirstName']换成$row[0]就可以。
但有时这样代码会变得不清晰,所以上来救助大家有无解决方法?!
我在网上google了很久,发现很少人遇到这样的问题,即使有,也只是书写错误什么的,不适合解决我这个问题。
------解决方案--------------------
使用 $rs->fetch_array 方法吧
------解决方案--------------------
用fetch_array()加上参数就好了:MYSQLI_ASSOC[关联], MYSQLI_NUM[数字], MYSQLI_BOTH[全部]
- PHP code
<?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT Name, CountryCode FROM City ORDER by ID LIMIT 3"; $result = $mysqli->query($query); /* numeric array */ $row = $result->fetch_array(MYSQLI_NUM); printf ("%s (%s)\n", $row[0], $row[1]); /* associative array */ $row = $result->fetch_array(MYSQLI_ASSOC); printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]); /* associative and numeric array */ $row = $result->fetch_array(MYSQLI_BOTH); printf ("%s (%s)\n", $row[0], $row["CountryCode"]); /* free result set */ $result->close(); /* close connection */ $mysqli->close(); ?> <br><font color="#e78608">------解决方案--------------------</font><br>没有错误信息吗?<br>看样子是没有打开错误显示功能 <br><font color="#e78608">------解决方案--------------------</font><br> 那只能是你的关联字段没有和数据库中的对应上。<br>实在没办法,用预编译处理吧:<br>
- PHP code
$sql = "SELECT mid,movName,movType,movStar,movImg,movPlay,director,producter FROM mov_film"; $stmt = $this->mysqli->prepare($sql); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($mid,$movName,$movType,$movStar,$movImg,$movPlay,$director,$producter); $rows = $stmt->affected_rows; if ($rows > 0){ $arrMovie = array(); while($stmt->fetch()){ //将文件名从路径中取出并转换为相对路径 $movImg = "../../images/".basename($movImg); //截取文件名 $arrStr = explode(".",basename($movPlay)); $movPlay = "../../videos/".$arrStr[0]; $arr = array( "mid" => $mid, "movName" => $movName, "movType" => $movType, "movStar" => $movStar, "movImg" => $movImg, "movPlay" => $movPlay, "director" => $director, "producter" => $producter ); array_push($arrMovie,$arr); } return $arrMovie; } <div class="clear"> </div>

许多用户在选择智能手表的时候都会选择的华为的品牌,其中华为GT3pro和GT4都是非常热门的选择,不少用户都很好奇华为GT3pro和GT4有什么区别,下面就就给大家介绍一下二者。华为GT3pro和GT4有什么区别一、外观GT4:46mm和41mm,材质是玻璃表镜+不锈钢机身+高分纤维后壳。GT3pro:46.6mm和42.9mm,材质是蓝宝石玻璃表镜+钛金属机身/陶瓷机身+陶瓷后壳二、健康GT4:采用最新的华为Truseen5.5+算法,结果会更加的精准。GT3pro:多了ECG心电图和血管及安

为什么截图工具在Windows11上不起作用了解问题的根本原因有助于找到正确的解决方案。以下是截图工具可能无法正常工作的主要原因:对焦助手已打开:这可以防止截图工具打开。应用程序损坏:如果截图工具在启动时崩溃,则可能已损坏。过时的图形驱动程序:不兼容的驱动程序可能会干扰截图工具。来自其他应用程序的干扰:其他正在运行的应用程序可能与截图工具冲突。证书已过期:升级过程中的错误可能会导致此issu简单的解决方案这些适合大多数用户,不需要任何特殊的技术知识。1.更新窗口和Microsoft应用商店应用程

在使用PHP编写Web应用程序时,经常会使用MySQL数据库来存储数据。PHP提供了一种与MySQL数据库进行交互的方法,称为MySQLi。然而,有时在使用MySQLi时,会遇到一个错误信息,如以下所示:PHPFatalerror:Calltoundefinedfunctionmysqli_connect()这个错误信息意味着PHP无法找到my

php无法连接mysqli的解决办法:1、打开“php.ini”文件;2、找到“mysqli.reconnect”;3、将“mysqli.reconnect = OFF”改成“mysqli.reconnect = on”即可。

PDOPDO是一个面向对象的数据库访问抽象层,它为PHP提供了一个统一的接口,允许您使用相同的代码与不同的数据库(如Mysql、postgresql、oracle)进行交互。PDO隐藏了底层数据库连接的复杂性,简化了数据库操作。优缺点优点:统一接口,支持多种数据库简化数据库操作,降低开发难度提供预处理语句,提高安全性支持事务处理缺点:性能可能比原生扩展稍低依赖外部库,可能会增加开销演示代码使用PDO连接mysql数据库:$db=newPDO("mysql:host=localhost;dbnam

mysql的运行文件是mysqld;mysqld是一个可执行文件,代表着Mysql服务器程序,执行这个文件可以直接启动一个服务器进程;而mysqld_safe是一个启动脚本,它会间接调用mysqld,并且还会顺带启动一个监控进程。

如果你使用PHP连接MySQL数据库时遇到了以下错误提示:PHPWarning:mysqli_connect():(HY000/2002):Connectionrefused那么你可以尝试按照下面的步骤来解决这个问题。确认MySQL服务是否正常运行首先应该检查MySQL服务是否正常运行,如果服务未运行或者启动失败,就可能会导致连接被拒绝的错误。你可

标题:C#中使用Array.Sort函数对数组进行排序的示例正文:在C#中,数组是一种常用的数据结构,经常需要对数组进行排序操作。C#提供了Array类,其中有Sort方法可以方便地对数组进行排序。本文将演示如何使用C#中的Array.Sort函数对数组进行排序,并提供具体的代码示例。首先,我们需要了解一下Array.Sort函数的基本用法。Array.So


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.