connect to pg working

This commit is contained in:
Brenda Wallace 2009-06-23 17:43:46 +12:00
parent 3fe182e865
commit 343e2010ae

View File

@ -204,21 +204,21 @@ function handlePost()
$fail = true; $fail = true;
} }
if (empty($password)) { // if (empty($password)) {
updateStatus("No password specified.", true); // updateStatus("No password specified.", true);
$fail = true; // $fail = true;
} // }
if (empty($sitename)) { if (empty($sitename)) {
updateStatus("No sitename specified.", true); updateStatus("No sitename specified.", true);
$fail = true; $fail = true;
} }
if($fail){ if($fail){
showForm(); showForm();
return; return;
} }
switch($dbtype) { switch($dbtype) {
case 'mysql': mysql_db_installer($host, $database, $username, $password, $sitename); case 'mysql': mysql_db_installer($host, $database, $username, $password, $sitename);
break; break;
@ -233,46 +233,55 @@ function handlePost()
<?php <?php
} }
function pgsql_db_installer($host, $database, $username, $password, $sitename) { function pgsql_db_installer($host, $database, $username, $password, $sitename) {
echo 'TODO'; exit; $connstring = "dbname=$database host=$host user=$username";
}
function mysql_db_installer($host, $database, $username, $password, $sitename) { //No password would mean trust authentication used.
updateStatus("Starting installation..."); if (!empty($password)) {
updateStatus("Checking database..."); $connstring .= " password=$password";
}
$conn = mysql_connect($host, $username, $password); updateStatus("Starting installation...");
if (!$conn) { updateStatus("Checking database...");
updateStatus("Can't connect to server '$host' as '$username'.", true); $conn = pg_connect($connstring);
showForm();
return; }
}
updateStatus("Changing to database..."); function mysql_db_installer($host, $database, $username, $password, $sitename) {
$res = mysql_select_db($database, $conn); updateStatus("Starting installation...");
if (!$res) { updateStatus("Checking database...");
updateStatus("Can't change to database.", true);
showForm(); $conn = mysql_connect($host, $username, $password);
return; if (!$conn) {
} updateStatus("Can't connect to server '$host' as '$username'.", true);
updateStatus("Running database script..."); showForm();
$res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn); return;
}
updateStatus("Changing to database...");
$res = mysql_select_db($database, $conn);
if (!$res) {
updateStatus("Can't change to database.", true);
showForm();
return;
}
updateStatus("Running database script...");
$res = runDbScript(INSTALLDIR.'/db/laconica.sql', $conn);
if ($res === false) {
updateStatus("Can't run database script.", true);
showForm();
return;
}
foreach (array('sms_carrier' => 'SMS carrier',
'notice_source' => 'notice source',
'foreign_services' => 'foreign service')
as $scr => $name) {
updateStatus(sprintf("Adding %s data to database...", $name));
$res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn);
if ($res === false) { if ($res === false) {
updateStatus("Can't run database script.", true); updateStatus(sprintf("Can't run %d script.", $name), true);
showForm(); showForm();
return; return;
} }
foreach (array('sms_carrier' => 'SMS carrier', }
'notice_source' => 'notice source',
'foreign_services' => 'foreign service')
as $scr => $name) {
updateStatus(sprintf("Adding %s data to database...", $name));
$res = runDbScript(INSTALLDIR.'/db/'.$scr.'.sql', $conn);
if ($res === false) {
updateStatus(sprintf("Can't run %d script.", $name), true);
showForm();
return;
}
}
updateStatus("Writing config file..."); updateStatus("Writing config file...");
$sqlUrl = "mysqli://$username:$password@$host/$database"; $sqlUrl = "mysqli://$username:$password@$host/$database";