【发布时间】:2011-05-30 13:13:42
【问题描述】:
问题应该很清楚,但我会再解释一次: 我正在尝试从 mysql 数据库中的数组中插入单个值。
代码如下:
public function addRoute($pointArray){
$length = 4; //just to be sure that nothing went wrong with calulating the length
for($i = 0; $i < $length; $i++){
$result = "INSERT into route_point(latlng, routeID) VALUES (4849, 10)"; //sample values, to once again be sure that there is nothing wrong with the values
mysql_query($result);
}
mysql_close(); //just to be sure again
return true;
}
如果有人想知道,pointArray 是使用 zendamf 框架从 actionscript 传递的。在我看来,该语句没有任何问题,但它不是插入 4 行,而是插入超过 100 000 行。我也没有在 actionscript 中收到“true”,它应该在执行 php 函数时传递.
我也尝试了 for each 循环,但我得到一个错误(我无法读取,因为我从 actionscript 调用 php 文件)。
foreach ($pointArray as $value) {
$result = "INSERT into route_point(latlng, routeID) VALUES ('$value', 10)";
mysql_query($result);
}
不过我更喜欢使用 for 循环。
对此一无所知,现在摆弄了几个小时的几个设置。
【问题讨论】:
-
Actionscript 不支持“稀疏”数组进行输出。如果您在 AS 中执行
arr[500] = 1,然后通过 AMF 或 JSON 或其他方式将其发送出去,则输出数据将使用定义的数组元素 1 到 499 构建,而不仅仅是 #500,因此您发送的是 500 个元素,不是 1. -
我已经能够通过 zendamf 使用 Chrome 开发者工具的网络选项卡查看 PHP 错误。它有助于在 Zend_Amf_Server 实例上运行
$server->setProduction(!DEBUG)。
标签: php mysql arrays loops for-loop