Connect to Multiple Databases using MySQLi

后端 未结 3 1705
花落未央
花落未央 2021-01-20 21:44

I need to connect to two databases using PHP and use the results from the first query to get the rest of the data I need out of a second database.

So for the second c

3条回答
  •  渐次进展
    2021-01-20 22:17

    This isn't tested, but I think it would go something like this.

    query($query) or die("Error in query");
    $thing1 = '';
    // check result
    if($result1->num_rows){
        //fetch result as object
        $row = $result1->fetch_object();
    
        //set attributes
        $thing1 = $row->Name;
    }   
    
    
    //build query 2
    $query2 = "SELECT * FROM AnotherTable WHERE Id = '$thing1'";
    
    $result2 = $dbc2->query($query) or die("Error in query");
    $thing2 = '';
    // check result
    if($result2->num_rows){
        //fetch result as object
        $row = $result2->fetch_object();
    
        //set attributes
        $thing2 = $row->Name;
    }
    
    ?>
    

提交回复
热议问题