简体   繁体   中英

pg_prepare(): Query failed: ERROR: Relation does not exist

I am trying to execute a query on a Postgres database using PHP. I get the following error:

pg_prepare(): Query failed: ERROR: relation "login" does not exist LINE 1: SELECT * FROM login 

This is a snippet of my code:

$connString = "host= port= dbname= user=password=";
$conn = pg_connect($connString);
if ($conn) {
    $sql = 'SELECT * FROM login ';
    if (pg_prepare($conn, "myQuery", $sql)) {
        $result = pg_execute($conn, "myQuery", array());
        if ($result) {
            while ($row = pg_fetch_row($result)) {

                echo $row[0];

                echo $row[1];
            }
        } else {
            echo 'executing error!';
        }
    } else {
        echo 'preparing error!';
    }
} else {
    echo "Connection error!";
}
if ($conn) {
    pg_close($conn);
}

When i run this script, it also prints 'preparing error!'

I guess there is something going on within the database. I have tried to create a new table. I also tried to use quotes in the query on several places, but nothing works.

This is the query I used to create the database:

CREATE TABLE login
(
    user_id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    username character varying(50) COLLATE pg_catalog."default",
    pwd character varying(50) COLLATE pg_catalog."default",
    CONSTRAINT pk_user_id PRIMARY KEY (user_id)
)

How do I fix this?

Try

SELECT * FROM public."login"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM