Mark Okhman
Mark Okhman

Reputation: 105

configuring zend application for postgres

I always used Application_Model_DbTable to work with database, but I used MySql. I configured my application.ini like this:

resources.db.adapter = PDO_MYSQL 
resources.db.params.host = localhost
resources.db.params.username = admin    
resources.db.params.password = 12345
resources.db.params.dbname = daedu
resources.db.params.charset = utf8

and used standart functions of dbtable such as fetchAll or insert. How to have same result, but with PostgreSQL?

I've installed PostgreSQL and through pgAdmin III I already made database and tables. The problem is how to connect it to Zend using db-table?

I configured it like this:

resources.db.adapter = PDO_PGSQL 
resources.db.params.host = localhost
resources.db.params.port = 5432
resources.db.params.username = postgres 
resources.db.params.password = 12345
resources.db.params.dbname = postgres
resources.db.params.charset = utf8

I work with it through dbtable like this:

class Application_Model_DbTable_Postrgres extends Zend_Db_Table_Abstract
{
    protected $_name = 'postgres';

    public function insert(){
        $data = array(
            'name' => "dan"
        );

        $this->insert($data);
    }
}

in Controller:

$f = new Application_Model_DbTable_Postrgres();
$f->insert();

but page doesnot open (error is: net::ERR_EMPTY_RESPONSE) and there is no new insert in table, when I try to fetchAll in db table, I get application error.

Upvotes: 1

Views: 3460

Answers (2)

Mark Okhman
Mark Okhman

Reputation: 105

Solved the problem! How? I turned on the development mode in public/index.php file:

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));

The error was shown that there is not Prymary Key in my table. I added it with SQl and threr it is! Everything works! So this way of connecting Zend to PostgreSQL is fully right!

Upvotes: 1

personman
personman

Reputation: 65

resources.db.adapter = PDO_PGSQL

You'll need to have PDO_PGSQL installed.

Upvotes: 1

Related Questions