1

好吧,我正在做的事情不可能像我做的那样(我已经连续两天了......再次)但是是否可以通过 PDO 运行多查询并返回所有结果……像这样?

$sql = 
"SELECT username, faction FROM users WHERE uid = :uid;". 
"SELECT level, exp, health, luck, first_name, last_name FROM player_information WHERE uid = :uid"; 
    $que = $this->db->prepare($sql);
    $que->bindParam('uid', $uid);
    try{
        $que->execute();
        $row = $que->fetchAll();
        print_r($row);
    }catch(PDOException $e){$e->getMessage(); }

还是我只是在叫错树?

4

2 回答 2

1

是的,这样的“多查询”称为JOIN

SELECT username, faction, level, exp, health, luck, first_name, last_name 
FROM users u, player_information pi WHERE u.uid = pi.uid AND u.uid = :uid

另外,您在调用它时使用了错误的运算符

$sql = "SELECT username, faction, level, exp, health, luck, first_name, last_name 
        FROM users u, player_information pi WHERE u.uid = pi.uid AND u.uid = ?";
$stm = $this->db->prepare($sql);
$stm->execute(array($uid));
$row = $que->fetch();
print_r($row);

将以更少的代码为您提供结果

于 2013-08-16T05:51:09.617 回答
0

You should take a look on transactions: http://www.php.net/manual/en/pdo.transactions.php

于 2013-08-16T02:13:40.280 回答