开发者

how to connect mysql Db through loops

hi i am using mysql for my database. just i try to connect mysql db through looping but it failed , i cannot , Is there is any otherway to do this

my trial code is this

while($row = mysql_fetch_array($query)) {

    $temp = "db".$row["listid"];
    $temp = m开发者_如何学Pythonysql_connect("localhost","root","", true); 
    mysql_select_db($row["databasename"],$temp);
}

is it any other way to do this.


Try with:

$res = mysql_query($query);
while($row = mysql_fetch_array($res)) {
  $name = "db".$row["listid"];
  $temp = mysql_connect("localhost","root","", true) or die('Could not connect: ' . mysql_error()); 
  mysql_select_db($row["databasename"],$temp);
  $res = mysql_query($query, $temp);
}

and tell us your error - but, as the first comment, this is highly NOT recommended


You only require ONE database connection.

Once you connect to a database it is available for the life of that page (request).

If you require to switch databases that will also use the same connection (unless different credentials are required.

If it's for cross database queries if they are on the same MySQL server and the user for the initial connection has sufficient privileges, then you can prefix database tables with the database name.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜