我无法弄清楚最简单的事情。尝试了各种各样的事情,但没有成功。我想简单地从表中选择一个具有特定名称的团队。这段代码只返回表格的标题,不会打印任何内容,就好像我的查询是空的一样。
我尝试过改变引号,但它会给我一个错误或者什么都不打印。
SELECT * from League where Name='AS Roma'
SELECT * from League where Name=AS Roma
SELECT * from League where Name="AS Roma"
有没有人有任何线索?
$db = new SQLite3('test.db');
$results = $db->query('SELECT * from League where Name="AS Roma"');
echo "<table border='1'>";
echo "<tr>";
echo "<th>Position</th><th>Club Name</th><th>G</th><th>W</th><th>D</th><th>L</th><th>GF</th><th>GA</th><th>P</th>";
echo "</tr>";
while ($row = $results->fetchArray()) {
echo "<tr>";
echo "<td>", $row[0], "</td><td>", $row[1],"</td>", "<td>", $row[2], "</td><td>", $row[3],"</td>","<td>", $row[4], "</td><td>", $row[5],"</td>", "<td>", $row[6], "</td><td>", $row[7],"</td>", "<td>", $row[8], "</td>";
echo "</tr>";
}
echo "</table>";
echo '<br>';
答案 0 :(得分:0)
我建议使用SQLite3 :: prepare。
$stmt = $db->prepare('SELECT * from League where Name LIKE :name');
$stmt->bindValue(':name', 'AS Roma', SQLITE3_TEXT);
$result = $stmt->execute();
while ( $row = $result->fetchArray()) {
...
}
答案 1 :(得分:-2)
您可能想尝试交换引号并使用反引号。
在:
$results = $db->query('SELECT * from League where Name="AS Roma"');
后:
$results = $db->query("SELECT * from League where Name=`AS Roma`");