php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #70881 Fatal error: Call to undefined function pg_connect()
Submitted: 2015-11-09 04:53 UTC Modified: 2015-11-09 05:00 UTC
From: gmgoodbody at yahoo dot com Assigned:
Status: Not a bug Package: PDO PgSQL
PHP Version: 5.6.15 OS: osx 10.11.1
Private report: No CVE-ID: None
 [2015-11-09 04:53 UTC] gmgoodbody at yahoo dot com
Description:
------------
---
From manual page: http://www.php.net/faq.databases
---
I upgraded to osx El Capitan and now my web development platform is all screwed up; I cannot access my postgres database from the php based webpage I am developing. I have spent over two days searching the internet for a solution but it's full of garbage. Everything I try does not work. I tried rigging the delivered php that comes with the mac, I tried installing php with homebrew using this command: brew install php56-pdo-pgsql 

Homebrew seemed to install everything but I still get the fatal undefined function pg_connect() error.


Test script:
---------------
Try to open php in Safari browser:
http://localhost/~mymacuser/testpg.php

This is what displays on my webpage:
Fatal error: Call to undefined function pg_connect() in /Users/mymacuser/Sites/testpg.php on line 8

<?php 
$host = "localhost";
$port = "5434";       //note: 5434 is the correct port
$user = "myuser"; 
$pass = "mypass"; 
$db = "mydb"; 

$con = pg_connect("host=$host port=$port dbname=$db user=$user password=$pass")
    or die ("Could not connect to server\n"); 

$query = "SELECT VERSION()"; 
$rs = pg_query($con, $query) or die("Cannot execute query: $query\n"); 
$row = pg_fetch_row($rs);

echo "Database version... <br>";
echo $row[0] . "\n";
echo "<br><br>";
?>



Expected result:
----------------
The expected result is php would know what pg_connect() means and I wouldn't get a fatal error. Or at least there would be an easy way to know what is wrong with my installation so I can fix it.

The PHP installation process is downright horrible. You need to fix/simplify your installation process or people are going to start using a different tool for web development.

I've been searching support pages all over the web for two days and there is a lot of garbage out there. It is extremely frustrating. Installing php should NOT be this difficult.


Actual result:
--------------
My phpinfo() has this:

Additional .ini files parsed	/usr/local/etc/php/5.6/conf.d/ext-pdo_pgsql.ini

pdo_pgsql
...
PDO

PDO support	enabled
PDO drivers	mysql, odbc, sqlite, pgsql
...
PDO Driver for PostgreSQL	enabled
PostgreSQL(libpq) Version	9.4.5
Module version	1.0.2
Revision	$Id: 93432550a76a2298959ec74f40d65c7195a82ad2 $


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-09 05:00 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-11-09 05:00 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You have the pdo_pgsql extension installed but are trying to use functions from pgsql extension. They are two different things.

http://php.net/pdo
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 18:01:38 2019 UTC