altergothen Posted February 3, 2009 Report Share Posted February 3, 2009 IS there an easier way to get a single result from a PDO query than having to run a foreach when I already know that there should only be a single record or value being returned? I tried using $myresult = $dbh->exec($sql); ...but only returns a 1 $dbh = new PDO("$Driver1:host=$Server1;dbname=$db1", $User1, $Password1); try { $sql = "SELECT FileVersion FROM FileVersion WHERE GroupID = $GroupID ORDER BY FileVersion Desc"; foreach ($dbh->query($sql) as $myrow) { $FileVersion = $myrow['FileVersion']; } $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } Quote Link to comment Share on other sites More sharing options...
monkeysaurus Posted February 3, 2009 Report Share Posted February 3, 2009 You can use a while loop instead; this is explained here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.