1

Alright, I'm what i'm doing isn't possible the way i'm doing it (I've been up for two days straight... again) but is it possible to run a multiquery through PDO and return all the results... like so?

$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(); }

or am i just barking up the wrong tree?

hjpotter92
  • 75,209
  • 33
  • 136
  • 171
Gmz1023
  • 123
  • 11
  • possible duplicate of [PDO support for multiple queries (PDO\_MYSQL, PDO\_MYSQLND)](http://stackoverflow.com/questions/6346674/pdo-support-for-multiple-queries-pdo-mysql-pdo-mysqlnd) – hjpotter92 Aug 16 '13 at 02:19
  • @hjpotter92 why not to read a question before reaching for the button? – Your Common Sense Aug 16 '13 at 05:55

2 Answers2

1

Yes, such a "multiquery" is called 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

also, you are using wrong operators when calling it

$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);

will give you the result in less code

Your Common Sense
  • 154,967
  • 38
  • 205
  • 325
0

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

Lukas Kolletzki
  • 1,920
  • 2
  • 25
  • 29