I'd need to put all the values from table Status in to variables. I'd guess this would not be the best way of doing it how I've done it below. I've tried using PDO::FETCH_ASSOC which I can't get to work. How should I do this correctly? Thanks.
My table named Status:
------------------ | Rule | Value | |----------------| | Active | 1 | |Version | 102 | | Limit | 15000 | ------------------
My code:
function checkStatus($connection, $rule) {
$query = $connection->prepare('SELECT Value FROM Status WHERE Rule=?');
$query->execute(array($rule));
$result = $query->fetchColumn();
return (int)$result;
}
try {
$connection = new PDO("mysql:host=localhost;dbname='something';charset=utf8", 'username', 'password');
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch(PDOException $ex) { //do-stuff }
$active = checkStatus($connection, "Active")
$version = checkStatus($connection, "Version")
$limit = checkStatus($connection, "Limit")
This works the way I want it to work, but how can I do this with just one query to the db and then put the results in the variables since I have around 10 of them at the moment?