php - Simplest method to retrieve single (and only) row in SQLite using PDO -


i have pdo

$stmt = $db->prepare('select * channels id=:id'); $stmt->bindvalue(':id', $id, sqlite3_integer); $result = $stmt->execute(); 

what simplest method access row returned using $row['column_name']?

i know sure query ever return single row it's impossible have more 1 row same id looking keep code simple possible access row.

examples i've seen online quite long , complex, using while loops loop through rows etc. don't need.

it should simple as

$row = $stmt->fetch(pdo::fetch_assoc); 

the examples you've seen have more like

while ($row = $stmt->fetch(pdo::fetch_assoc)) { ... 

because they're designed process query result multiple rows. if know you'll ever have 1 row, can forgo loop. of course, assuming query executed , returned result. idea @ least check

if ($row) { ... 

before try use in subsequent code.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -