Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: added postgresql schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Marion committed Mar 14, 2011
1 parent 77b8c37 commit ce27909
Show file tree
Hide file tree
Showing 2 changed files with 397 additions and 2 deletions.
41 changes: 39 additions & 2 deletions application/controllers/InstallController.php
Expand Up @@ -95,6 +95,7 @@ function step2Action()
switch($type)
{
case 'mysql':
case 'pgsql':
$this->run_mysql_from_file(BASE_PATH."/sql/{$type}/{$this->view->version}.sql",
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'));
$params= array(
Expand All @@ -121,6 +122,33 @@ function step2Action()
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('dbAdapter', $db);
break;
case 'pgsql':
$this->run_pgsql_from_file(BASE_PATH."/sql/{$type}/{$this->view->version}.sql",
$form->getValue('host'), $form->getValue('username'), $form->getValue('password'), $form->getValue('dbname'));
$params= array(
'host' => $form->getValue('host'),
'username' => $form->getValue('username'),
'password' => $form->getValue('password'),
'dbname' => $form->getValue('dbname'),
);

$databaseConfig['production']['database.type']='pdo';
$databaseConfig['development']['database.type']='pdo';
$databaseConfig['production']['database.adapter']='PDO_PGSQL';
$databaseConfig['development']['database.adapter']='PDO_PGSQL';
$databaseConfig['production']['database.params.host']=$form->getValue('host');
$databaseConfig['development']['database.params.host']=$form->getValue('host');
$databaseConfig['production']['database.params.username']=$form->getValue('username');
$databaseConfig['development']['database.params.username']=$form->getValue('username');
$databaseConfig['production']['database.params.password']=$form->getValue('password');
$databaseConfig['development']['database.params.password']=$form->getValue('password');
$databaseConfig['production']['database.params.dbname']=$form->getValue('dbname');
$databaseConfig['development']['database.params.dbname']=$form->getValue('dbname');

$db = Zend_Db::factory("PDO_PGSQL",$params);
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('dbAdapter', $db);
break;
default:
break;
}
Expand Down Expand Up @@ -227,6 +255,15 @@ public function testconnexionAction()
}
$return =array(true,"The database is reachable");
break;
case 'pgsql':
$link = @pg_connect("host=$host port=5432 dbname=$dbname user=$username password=$password");
if (!$link)
{
$return= array(false, "Could not connect to the server '" . $host . "': ".pg_last_error($link));
break;
}
$return =array(true,"The database is reachable");
break;
default:
$return = array(false,"Database not defined");
break;
Expand Down Expand Up @@ -267,9 +304,9 @@ function run_mysql_from_file($sqlfile,$host,$username,$password,$dbname)
return true;
}
/** Function to run the sql script */
function run_pgsql_from_file($sqlfile)
function run_pgsql_from_file($sqlfile,$host,$username,$password,$dbname)
{
$pgdb = pg_connect($this->getDatabaseConnectionString());
$pgdb =$link = @pg_connect("host=$host port=5432 dbname=$dbname user=$username password=$password");
$file_content = file($sqlfile);
$query = "";
$linnum = 0;
Expand Down

0 comments on commit ce27909

Please sign in to comment.