R
R
Respect and good to all2018-05-02 11:35:13
PHP
Respect and good to all, 2018-05-02 11:35:13

How to display values ​​with all id's from a PostgeSQL table?

It produces the following error:
5ae9778268df1114446117.png

Here is the code itself:
<html>
 <head>
  <title>МОАТП</title>
 </head>
 <body>
 <?php echo '<p>Коннектимся к базе PostgreSQL:</p>'; ?>
 
 
<?php 

// Соединение, выбор базы данных
$dbconn = pg_connect("host=pg.sweb.ru port=5432 dbname=moatpru_test user=moatpru_test password=*od***obe**anj*") 
or die('Could not connect: ' . pg_last_error()); 

var_dump($dbconn); 


echo '<p>Выполняем SQL запрос:</p>'; 

$table= "Users";
// generate and execute a query 
$query = "SELECT id FROM $table";
$result = pg_query($connection, "SELECT users FROM $table") or die("Error in query: $query.
" . pg_last_error($connection));

// get the number of rows in the resultset 
$rows = pg_num_rows($result); 

echo "There are currently $rows records in the database."; 

// close database connection 
pg_close($connection); 
?>


 <?php echo '<p>FINISH</p>'; ?>


Here is the base:
5ae978391535b716534839.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2018-05-02
@Rsa97

Find the `id` column in your table. It is not there, there is `id_users`.

M
Melkij, 2018-05-02
@melkij

You deleted the previous question and I have no desire to type the answer again. Therefore, I will be brief.
One error was pointed out by Rsa97 , the second error:

SELECT id FROM Users;
SELECT id FROM "Users";

These are references to different tables.
Figure out where you lost the actual pg error messages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question