Enable PHP support for postgresql in Ubuntu 11.04 server

前端 未结 3 1021
有刺的猬
有刺的猬 2021-01-01 13:04

I\'ve installed Apache2 with php5 support and everything works there. I\'ve installed PostgreSQL and am able to connect to it using the terminal and execute SQL statements.

相关标签:
3条回答
  • 2021-01-01 13:38

    Install the php5-pgsql package solves the problem. (depending on the version ... php4-pgsql for php4)

    apt-get install php5-pgsql
    

    Remember to restart Apache.

    /etc/init.d/apache2 restart
    

    --Note that it might be hard if you do not administer your server.

    0 讨论(0)
  • 2021-01-01 13:38

    Currently, I am using Ubuntu 16.04 LTS. Me too was facing same problem while Fetching the Postgress Database values using Php so i resolved it by using the below commands.

    Mine PHP version is 7.0, so i tried the below command.

    apt-get install php-pgsql

    Remember to restart Apache.

    /etc/init.d/apache2 restart
    

    Below is my code , might be someone get benefited :

    - testdb.php

    <html> 
        <body> 
            <table border="0" cellspacing="0" cellpadding="0"> 
                <tr> 
                    <td> 
                        Friend ID 
                    </td> 
                    <td> 
                         Name 
                    </td> 
    
                </tr> 
            <?php 
            $db = pg_connect('host=localhost dbname=postgres user=postgres password=root port=5432'); 
    
            $query = "SELECT * FROM account"; //account is name of table 
    
            $result = pg_query($query); 
            if (!$result) { 
                echo "Problem with query " . $query . "<br/>"; 
                echo pg_last_error(); 
                exit(); 
            } 
    
            while($myrow = pg_fetch_assoc($result)) { 
                printf ("<tr><td>%s</td><td>%s</td></tr>", $myrow['id'], htmlspecialchars($myrow['name']));
            } 
            ?> 
            </table> 
        </body> 
    </html> 
    
    0 讨论(0)
  • 2021-01-01 13:45

    The only conclusion I can come up with is that phppgadmin installed all of the needed packages to make PHP5 connect to PostgreSQL. I have looked at the dependencies, and I believe that I either didn't install them at all or didn't install them correctly.

    I require no more help in this arena, as I have a working setup and know at least one method of getting to that point.

    0 讨论(0)
提交回复
热议问题