Purpose:
Select a single line with LIMIT 1
Internal Use:
The selects
receive internal parameters only
You do not need PREPARE
because there are no external user data
$pdo = new PDO("mysql:host=A.com;dbname=B; charset=utf8", "C", "PW");
exemplo 1:
$con = $pdo->query("SELECT id,titulo FROM cursos WHERE cod=1 LIMIT 1");
foreach($con as $row) {
echo $row['id'].' - '.$row['titulo'];
}
Example 2:
$con = $pdo->query("SELECT id,titulo FROM cursos WHERE cod=1 LIMIT 1");
$con->execute();
$sel=$con->fetch();
echo $sel['id'].' - '.$sel['titulo'];
Example 3:
$con = $pdo->query("SELECT id,titulo FROM cursos WHERE cod=1 LIMIT 1")->fetch();
echo $con['id'].' - '.$con['titulo'];
The selected row contains 80 columns (with or without data)
The 3 works OK, but I have questions about which one to use.
If there is another way, shorter or faster.