Fatal error: Call to undefined function pg_connect()

后端 未结 17 1428
广开言路
广开言路 2020-12-02 23:07

I am trying to connect to my database (remote server) which has PostgreSQL installed in it. My PHP code is trying to connect to the database using pg_connect(), but I get th

相关标签:
17条回答
  • 2020-12-02 23:29

    I had the same symptom in win7. I got this script:

    <?php
        phpinfo();
        pg_connect("blah");
    

    When I executed the phpinfo.php script via apache (http://localhost/phpinfo.php) then I got the error message: Call to undefined function pg_connect() in...

    When I executed the same script from command line (php phpinfo.php) then I got the expected message: PHP Warning: pg_connect(): Unable to connect to PostgreSQL server: missing "=" after "blah"

    In both cases the expected php.ini was used:

    Loaded Configuration File   C:\Program Files (x86)\php\php.ini 
    

    but the pgsql section was completely missing from the phpinfo in case of the apache-based execution and it was present in the command-line-based execution.

    The solution was that I added the following line to the apache httpd.conf:

    LoadFile "C:/Program Files (x86)/php/libpq.dll"
    

    It seems that for some reason this file is not loaded automatically when apache runs the php script but it is loaded if I run the php script from the command line.

    I hope it helps.

    0 讨论(0)
  • 2020-12-02 23:31

    In windows OS find this in php.ini "php_pgsql.dll" and remove the ";" in the extension then that's it :) Cheeers!

    0 讨论(0)
  • 2020-12-02 23:33

    Uncommenting extension=php_pgsql.dll in the php.ini configuration files does work but, you may have to also restart your XAMPP server to finally get it working. I had to do this.

    0 讨论(0)
  • 2020-12-02 23:35

    You have to follow these steps:

    Open the php configuration file, which is located in the following directory

    C: \ xampp \ php \ php.ini
    

    Within that file search the extension section and uncomment the following lines

    extension = php_pdo_pgsql.dll  
    extension = php_pgsql.dll
    

    and restart your apache

    0 讨论(0)
  • 2020-12-02 23:36

    install the package needed. if you use yum:

    yum search pgsql
    

    then look at the result and find anything that is something like 'php-pgsql' or something like that. copy the name and then:

    yum install *paste the name of the package here*
    
    0 讨论(0)
  • 2020-12-02 23:36

    The solution has to do with the fact that your the file holding your php configurations. i.e php.ini has uncommented the extension responsible for acting as the middleman between php and postgres, by placing a ";" in front of the statement "extension=pdo_pgsql"

    Quick Fix

    1. Open the php.ini file in your favourite editor. (atom
    0 讨论(0)
提交回复
热议问题