php - 错误:关系“雇员”不存在第 1 行:从“雇员”中选择 * ^
问题描述
我尝试从 pg_admin4 中选择数据表,但它不起作用。
这是我的代码 - 文件:index.php
<DOCTYPE html>
<head>
<title>Accounting for the execution of tasks</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1 style="color:rgb(187, 91, 74); text-align:center">Projects Database</h1>
<hr></hr>
<h2>List actions:</h2>
</body>
</html>
<?php
$dbuser = 'postgres';
$dbpass = 'thien123';
$host = 'localhost';
$dbname='data_main';
$dbschema='data1';
$db = pg_connect("host=$host dbname=$dbname user=$dbuser password=$dbpass") or die("Couldn't connect: ". pg_last_error());
//$query = "INSERT INTO imployee VALUES ('$_POST[id_imployee]', '$_POST[book_name]')";
//$result = pg_query($query);
//pg_close($db);
?>
<html>
<h3> Select a table </h3>
<form method = "POST" action="">
<select name="select_db" >
<option value="None"> Select a table </option>
<?php
$query = "select * from information_schema.tables
where table_schema = 'data1' and table_type = 'BASE TABLE'
order by table_name;";
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
while($row = pg_fetch_assoc($result)):
?>
<option value="<?php echo $row['table_name']; ?>">
<?php echo $row['table_name']; ?></option>
<?php endwhile; ?>
</select>
<input type="submit" name="submit">
</form>
</html>
<?php
$table = $_POST["select_db"];
if(isset($table) && $table != 'None')
{
echo "<p><b><i> $table </i> table</b></p>";
$query = "select * from \"$table\"";
$result = pg_query($query) or die('Error! '. pg_last_error());
$i = 0;
echo '<style>
table, th, td
{
border: 1px solid black;
}
</style>';
echo '<html><body><table><tr>';
while ($i < pg_num_fields($result))
{
$field_name = pg_field_name($result, $i);
echo '<td>' . $field_name . '</td>';
$i++;
}
echo '</tr>';
$i = 0;
while ($row = pg_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$r = 0;
while ($y < $count)
{
$cur_row = current($row);
echo '<td>' . $cur_row . '</td>';
next($row);
$r++;
}
echo '</tr>';
$i++;
}
pg_free_result($result);
echo '</table></body></html>';
}
?>
当我在浏览器中运行它时,我得到了错误
Query failed: ERROR: relation "imployee" does not exist LINE 1: select * from "imployee" ^
当我选择表员工时出错
这是我在 pg admin4 中所做的查询
我使用 xammpp 8.0.6
我不知道如何解决它。
解决方案
推荐阅读
- python - 迭代元组列表并根据条件创建字典
- reactjs - Mongodb正确分页
- javascript - 如何根据字符串命名函数?
- scikit-learn - 将 X.toarray 反转为 sklearn 中的 CountVectorizer
- android - react-native run-android 构建失败
- scheme - 了解教会数字
- google-analytics - 我如何在谷歌分析收集上覆盖 uip
- windows - Windows 中的 Git Bash 无法启动
- mysql - 如何根据 2 个不同的表获取不存在的记录
- c# - 有没有办法告诉编译器在 C# 中使用“快速数学”或类似的东西进行编译?