可以将相同的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.
编辑:我想从输出中指出第一个查询执行但第二个查询没有执行。在这两者之间,链接没有变化。查询如何执行有点无关紧要(恕我直言)。
编辑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);
答案 0 :(得分:2)
您在$querries
循环中错误拼写for
。它应该是$queries
。
答案 1 :(得分:2)
for
循环的每次迭代都包含对buildQuery()
的调用(此处未显示)。它是以某种方式影响$ link,还是更改$ debug的值?
此外,你的循环引用$ numRows,这里没有定义。循环执行了多少次?