I've decided to migrate my project to prepared statements, and I am with an error after executing the following code:
$sql = 'SELECT clanID FROM clan_users WHERE userID = :uid LIMIT 1';
$data = $this->pdo->prepare($sql);
$data->execute(array(':uid' => $uid));
$data->fetchAll();
return $data['0']['clanid'];
Error returned:
Fatal error: Cannot use object of type PDOStatement as array in
/var/www/game/classes/Clan.class on line 689
var_dump($data) returns:
object(PDOStatement)[122]
public 'queryString' => string 'SELECT clanID FROM clan_users WHERE userID = :uid LIMIT 1' (length=57)
The value of $uid is correct, and selecting manually at mysql returns the expected row. I also tried changing to
$data->fetch(PDO::FETCH_OBJ);
but didnt work too.
Any ideas? Thanks in advance.