MYSQL PHP PDO如何获得1条记录

时间:2013-12-29 12:25:11

标签: php mysql pdo

您好我从数据库获取值时遇到了问题:

$marka=$_POST['marka'];

$marka=$connection->quote($marka);

$id_marki=$connection->query('Select id from Model where nazwa='.$marka)->fetch();

echo $id_marki['id'];
回声没有告诉我什么。

1 个答案:

答案 0 :(得分:0)

$connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$stmt = $connection->prepare('Select id from Model where nazwa=?');
$stmt->execute(array($_POST['marka']));
$id = $stmt->fetchColumn();
echo $id;