<?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!