Can the same mysql resource be used for multiple queries?
$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);
Output:
link is of type resource
Successfully executed query
link is of type resource
Did not execute query.
EDIT: I wanted to point out from the output that the first query executes but the second does not. In between, there is no change to the link. How the queries execute kinda doesn’t matter, either (IMHO).
EDIT 2: My exact code below:
$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);
Each iteration of the
forloop contains a call tobuildQuery()(not shown here). Does it affect $link in some way, or change the value of $debug?Additionally, your loop references $numRows, which is not defined here. How many times does the loop execute?