首页 > 解决方案 > 错误:关系“雇员”不存在第 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 中所做的查询 这是我在 pg admin4 中所做的查询

我使用 xammpp 8.0.6 我使用 xammpp 8.0.6

我不知道如何解决它。

标签: phphtmlsql

解决方案


推荐阅读