开发者

Link resource in mysql is being tempermental

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 />";
开发者_C百科        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 for loop contains a call to buildQuery() (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?


You mis-spelled $querries in your for loop. It should be $queries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜