我想用表'users'和属性'name'(VARCHAR(20))和'id'(INTEGER)从我的数据库'phpopdracht5'中检索数据,但它只是不起作用。我的代码一定有问题
<?php
define("DB_HOST", "localhost");
define("DB_USERNAME", "root");
define("DB_PASSWORD", "");
define("DB_NAME", "phpopdracht5");
try
{
$db_conn = new PDO('mysql:host='.DB_HOST.';dbname'.DB_NAME,DB_USERNAME,DB_PASSWORD);
}
catch(PDOException $e)
{
print "Error!:".$e->getMessage()."\n";
die();
}
$sth = $db_conn->prepare('SELECT * FROM users');
$sth->bindParam(':name', $name, PDO::PARAM_STR, 20);
$sth->bindParam(':id', $id, PDO::PARAM_INT);
$sth->execute();
while ($row = $sth->fetch(PDO::FETCH_BOTH)) {
echo $row[0];
}
?>