我是PHP的新手,只是在学习。
<?php
// database connection
$dbhost = "localhost";
$dbname = "pdo";
$dbuser = "root";
$dbpass = "7777777";
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass)
// echo from database
$select = $conn->query('SELECT username FROM users');
while($row = $select->fetch(PDO::FETCH_ASSOC))
{
$username = $_GET['username'];
echo $username;
}
?>
这会出错:
解析错误:语法错误,意外的T_PUBLIC在行:$ select = $ conn-&gt; query('SELECT username FROM users');
答案 0 :(得分:2)
需要更改连接
From:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass)
To:
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
连接缺少;