RsD0p9BK
11/8/2016 - 4:43 AM

pdo__fetch_one_row.php

// PHP PDO returning single row

$pdo = new PDO($dsn, $username, $password);
$stmt = $pdo->prepare("SELECT name FROM mytable WHERE id=4 LIMIT 1"); 
$stmt->execute(); 
$row = $stmt->fetch();


// OR

$pdo = new PDO("connection string goes here");
$stmt = $pdo->prepare("select figure from table1");
$stmt->execute();
$result = $stmt->fetchAll()[0];

// http://stackoverflow.com/questions/5456626/php-pdo-returning-single-row