PHP程序无法连接到Postgresql数据库


PHP program cannot connect to Postgresql DB

我的PHP程序正试图连接到另一台机器上的PostgreSQL数据库,但当网页加载时,它只显示"Could not find driver"。

我四处搜索,发现我必须取消对extension=php_pdo_pgsql.dll的注释和CCD_ 4中的CCD_。不确定我还能错过什么。请引导。

database.php

<?php
class Database
{
    private static $dbName = 'istore-db' ;
    private static $dbHost = 'gsi-547576.gsiccorp.net' ;
    private static $dbUsername = 'postgres';
    private static $dbUserPassword = 'postgres';
    private static $dbPort = '5432';
    private static $cont  = null;
    public function __construct() {
        die('Init function is not allowed');
    }
    public static function connect()
    {
       // One connection through whole application
       if ( null == self::$cont )
       {     
        try
        {
          //self::$cont =  new PDO( "pgsql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword); 
          self::$cont = new PDO("pgsql:dbname=" . self::$dbName . ";host=" .self::$dbHost . ";port=" .self::$dbPort, self::$dbUsername,  self::$dbUserPassword);
        }
        catch(PDOException $e)
        {
          die($e->getMessage()); 
        }
       }
       return self::$cont;
    }
    public static function disconnect()
    {
        self::$cont = null;
    }
}
?>

index.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link   href="css/bootstrap.min.css" rel="stylesheet">
        <script src="js/bootstrap.min.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <h3>PHP CRUD Grid</h3>
            </div>
            <div class="row">
                <p>
                    <a href="create.php" class="btn btn-success">Create</a>
                </p>
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Description</th>
                            <th>Active</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        include 'database.php';
                        $pdo = Database::connect();
                        $sql = 'SELECT * FROM categories ORDER BY  NAME';
                        foreach ($pdo->query($sql) as $row) {
                            echo '<tr>';
                            echo '<td>' . $row['category_id'] . '</td>';
                            echo '<td>' . $row['name'] . '</td>';
                            echo '<td>' . $row['description'] . '</td>';
                            echo '<td>' . $row['active'] . '</td>';
                            echo '<td width=250>';
                            echo '<a class="btn" href="read.php?id=' . $row['id'] . '">Read</a>';
                            echo ' ';
                            echo '<a class="btn btn-success" href="update.php?id=' . $row['id'] . '">Update</a>';
                            echo ' ';
                            echo '<a class="btn btn-danger" href="delete.php?id=' . $row['id'] . '">Delete</a>';
                            echo '</td>';
                            echo '</tr>';
                        }
                        Database::disconnect();
                        ?>
                    </tbody>
                </table>
            </div>
        </div> <!-- /container -->
    </body>
</html>

更改此行:

self::$cont =  new PDO( "pgsql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword); 

self::$cont = new PDO("pgsql:dbname=" . self::$dbName . ";host=" .self::$dbHost, self::$dbUsername,  self::$dbUserPassword);