Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

413
Views
php pg_connect() works in terminal but not in the browser
<?php
    echo "Inside php file!<br>";

    $dbconn = pg_connect("host=localhost dbname=atharvacm user=atharvacm port=5432 password=Dominicmcs9") or die("Cannot connect to DB");

    echo "after con<br>";

    $query = "select * from person;";
    $result = pg_query($dbconn, $query) or die("cannot exec query");
    while ($answer = pg_fetch_row($result)) {
        echo $answer[0];
        echo $answer[1];
        echo " huh<br>";
    }
    echo "<br>end";
?>

this is the code im trying to execute. It outputs the records in the table person in terminal but in the browser it only echoes "Inside php file" and nothing after it.

Here is the terminal output:

atharvacm@kali:/var/www/html$ php psqltest.php 
Inside php file!<br>after con<br>1abc huh<br>2def huh<br>3pqr huh<br>4xyz huh<br><br>end
atharvacm@kali:/var/www/html$ 

Here is the output from the web browser

Inside php file!

Fatal error: Uncaught Error: Call to undefined function pg_connect() in /var/www/html/psqltest.php:4 Stack trace: #0 {main} thrown in /var/www/html/psqltest.php on line 4

I have kali linux and running apache2, psql, php7.

I installed the php-pgsql package and uncommented the extention in the php.ini file.

I cant seem to figure out what the problem is but my guess is that the pg_connect function is not finding the psql database or something form the browser. thanks!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat In some case the software is not configured for psql

So go in the file and uncomment the line Extension= pgsql

Also enable ur error log in Apache U can refer Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat In some case the software is not configured for psql

So go in the file and uncomment the line Extension= pgsql

Also enable ur error log in Apache U can refer

Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat In some case the software is not configured for psql

So go in the file and uncomment the line Extension= pgsql

Also enable ur error log in Apache U can refer

Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat In some case the software is not configured for psql

So go in the file and uncomment the line Extension= pgsql

Also enable ur error log in Apache U can refer

How do I get PHP errors to display?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!