同一个mysql资源可以用于多个查询吗?
$queries=array($q1, $q2);
$link=mysql_connect(...);
mysql_select_db(...);
for($i = 0; $i < count($queries); $i++) {
echo "Link is of type " . gettype($link) . "<br />";
if(is_resource($link)) {
mysql_query($queries[$i], $link);
} else {
echo "Did not execute query. <br/>";
}
}
disconnect($link);
输出:
link is of type resource
Successfully executed query
link is of type resource
Did not execute query.
EDIT:我想从输出中指出,第一个查询执行,但第二个不执行。在两者之间,链接没有更改。查询的执行方式也不重要(IMHO)。
编辑2:我下面的确切代码:
$link = mysql_connect("localhost", ........);
mysql_select_db(....);
for ($row = 0; $row < $numRows; $row++) {
if (($query = buildQuery($mainArr, $rowArr, $row)) === null) {
echo "Error - could not build query. <br />";
return;
}
echo "Link is of type " . gettype($link) . "<br />";
if (is_resource($link)) {
if ((mysql_query($query, $link))) {
if($debug) {
echo "Successfully executed query <br />";
}
} else {
if ($debug) {
echo "This comes up when row is " . $row . "<br />";
echo "Link is of type " . gettype($link) . "<br />";
echo "Datawrite failed - " . $query . "<br />";
echo "the official line is " . mysql_error($link) . "<br />";
}
}
} else {
echo "Did not execute query <br />";
}
}
disconnect($link);
for
循环的每个迭代都包含对buildQuery()
的调用(此处未显示)。它是否以某种方式影响$link,或者更改$debug的值?
此外,您的循环引用$numRows,此处未对此进行定义。循环执行了多少次?
您在for
循环中拼错了$querries
。它应该是$queries
。