- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
http://www.securityandcaffeine.com/2008/04/03/php-mysql-and-mysql_fetch_array/
上面的文章让我很吃惊。它说:
mysql_fetch_array()
- "1 – Use quotes! 1/7th of the time to get$result['2']
compared to$result[2]
"
不知道这是不是真的?
最佳答案
这似乎完全是基于一种误解。看到这句话,突出我的:
1 – You are wasting speed if you reference the values, but don’t use quotes. According to Reinhold Weber’s Blog: #17: “
$row[’id’]
is 7 times faster than$row[id]
“. If you’re doing this a lot, and often… ouch.
是的,$row['id']
比 $row[id]
快,因为 $row[id]
是一个语法错误,它试图解析一个常量,然后把它变成一个字符串,同时抛出一个通知。 但是 $row[1]
和 $row['id']
都是有效 并且应该执行非常相同。如果查找数字索引和查找字符串索引之间存在差异,则差异一定很小,不值得您花时间。
关于 PHP 数组实际上没有位置键但都是关联键的启示是……不是真正的新闻,因此没有广泛传播的速度问题。事实上,这个快速基准表明“数字字符串”索引很容易成为所有索引中最慢的查找:http://codepad.org/aeNJ2u3O
无论如何,您应该使用 mysql_fetch_assoc
或 mysql_fetch_row
,它们分别为您提供命名(字符串索引)或未命名(数字索引)数组。通常不需要使用 _fetch_array
来获取两者。
如果您想要真实的性能数据,请针对您的用例对其进行基准测试。
关于php - mysql_fetch_array() 引用增加速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11345894/
我是初学者,我有一个错误 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
所以我有 3 个数据库表,除了表的名称外,它们在各个方面都是相同的(数据不同)。我这样做是为了可以像这样使用带有开关的一段代码: function disp_bestof($atts) { extr
我有一个数据库,其中包含带有指向其中每一集的链接的行。我正在尝试使用下面的代码来获取一种类型节目的所有链接,并且我成功地做到了这一点。我似乎无法弄清楚的是如何只显示其中一行,而不是让它们全部显示在一行
$n=mysql_num_rows($rs); $i=0; while($n>0) { while(($row=mysql_fetch_a
你好, 我是 php 新手,我在使用 mysql_fetch_array() 时遇到了一些问题。 $sql = "SELECT mandant_kurz FROM pu_mandant ORDER B
我有这样的问题。我写: $id = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type='video'"); whil
当我尝试 print_r mysql_fetch_array 的 sql 查询时,我得到了这个结果。 Array ( [0] => 1 [id] => 1 [1] => 201
我有以下代码: $mostRecent = mysql_query("SELECT couponID FROM users_coupons WHERE userID = '$userID' ORDER
我真的非常需要以下代码的帮助。我只是不明白为什么它不起作用。 我需要查询一个 MySQL 表,我只需要为特定 ID 返回一行。然而 mysql_fetch_array 只返回该表的第一列 - 我快要沮
我正在使用此代码来显示管理员用户: 1"))){ echo ''.$write['username'].''; } ?> 但是页面一直在加载!有什么问题吗? 最佳答案 这是一个无限循环。您一遍
我不是 PHP 的新手,但我没怎么用过 MySQL,所以我会问问你们这个问题。 我有一个包含一行数据的数据库,其中包含一个日期和两个整数。但是,当我用这个查询数据库时: $query = "SELEC
下面的脚本是在数据库中搜索查询 ( $matric_no ),以便它返回名称(名字,姓氏, 其他名称)和其他学生信息。它工作正常,只要它返回一行,但每当返回两行或更多行时 名称(所有行都相同)的迭代次
如何对从 mysql_fetch_array() 返回的数组执行搜索并用 php 替换?如果我使用 preg_replace()它不会返回匹配项。我缺少什么吗?这是我使用过但没有成功的方法,任何人都可
我遇到了这样一种情况:将 mysql_query() 结果馈送到 mysql_fetch_array() 函数中,该结果被解释为 bool 值而不是结果。 下面的代码使用 Using an SQL r
问题标题说明了一切:我想循环遍历每一行,但我只得到每隔一行。有趣的是,当我使用 mysql_num_rows 时,如下所示,它得到了正确的计数。怎么了? $query = "SELECT * FROM
我试图显示来自 mysql 的值,但它返回任何空页面。连接正常,但无法从 mysql 获取数据。我尝试了类似问题的所有答案。但没有任何帮助。有人能帮帮我吗?这是代码 $con= mysql_
我收到以下错误消息: Notice: Undefined index: timein in time.php on line 42 Notice: Undefined index: timeout i
我有一个 while 循环,其中包含另一个 while 循环。两个循环都迭代不同的 mysql 结果集。问题是,外部 while 循环第二次调用内部 while 循环时,它不会运行。 Mysql_fe
好的,我执行这个 $table = get_personel_table(1); function get_personel_table($id) { global $conn
我在这里彻底崩溃了。我试图从使用 mysql_fetch_array() 的查询中获取结果,但它带来了 from 值。这是一个简单的示例: 这是查询: $query = SELECT COUNT(*)
我是一名优秀的程序员,十分优秀!