Joey Joey - 1 month ago 5
PHP Question

PHP PDO how to handle results?

How to handle results with PHP PDO?

$sth = $dbh->prepare("SELECT * FROM users WHERE test = :steamid");
$sth->bindParam(':test', $colour);
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
print_r($result);


So the print outputs something like:
Array ( [id] => 1 [test] => red [rank] => 1 )

How do I handle this output? If I - for example - want to compare
red
to blue?

Answer

So the print outputs something like: Array ( [id] => 1 [test] => red [rank] => 1 ) How do I handle this output?

Simple array, nothing so special.

echo $result['rank'];

for example - want to compare red to blue?

if($result['test']=='blue')
Comments