Skip to content

Commit

Permalink
actually check for DB_PORT in installer, add better hints and use mys…
Browse files Browse the repository at this point in the history
…qli if available
  • Loading branch information
cthu1hoo committed Apr 18, 2013
1 parent 1daf0f7 commit bbffc43
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config.php-dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
define('DB_USER', "fox");
define('DB_NAME', "fox");
define('DB_PASS', "XXXXXX");
//define('DB_PORT', '5432'); // when neeeded, PG-only
define('DB_PORT', ''); // usually 5432 for PostgreSQL, 3306 for MySQL

define('MYSQL_CHARSET', 'UTF8');
// Connection charset for MySQL. If you have a legacy database and/or experience
Expand Down
36 changes: 24 additions & 12 deletions install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function print_notice($msg) {
<img src=\"../images/sign_info.svg\">$msg</div>";
}

function db_connect($host, $user, $pass, $db, $type) {
function db_connect($host, $user, $pass, $db, $type, $port) {
if ($type == "pgsql") {

$string = "dbname=$db user=$user";
Expand All @@ -101,19 +101,24 @@ function db_connect($host, $user, $pass, $db, $type) {
$string .= " host=$host";
}

if (defined('DB_PORT')) {
$string = "$string port=" . DB_PORT;
if ($port) {
$string = "$string port=" . $port;
}

$link = pg_connect($string);

return $link;

} else if ($type == "mysql") {
$link = mysql_connect($host, $user, $pass);
if ($link) {
$result = mysql_select_db($db, $link);
if ($result) return $link;
if (function_exists("mysqli_connect")) {
return mysqli_connect($host, $user, $pass, $db, $port);

} else {
$link = mysql_connect($host, $user, $pass);
if ($link) {
$result = mysql_select_db($db, $link);
if ($result) return $link;
}
}
}
}
Expand Down Expand Up @@ -173,7 +178,12 @@ function db_query($link, $query, $type, $die_on_error = true) {
}
return $result;
} else if ($type == "mysql") {
$result = mysql_query($query, $link);

if (function_exists("mysqli_connect")) {
$result = mysqli_query($link, $query);
} else {
$result = mysql_query($query, $link);
}
if (!$result) {
$query = htmlspecialchars($query);
if ($die_on_error) {
Expand Down Expand Up @@ -254,17 +264,19 @@ function make_self_url_path() {

<fieldset>
<label>Database name</label>
<input name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/>
<input required name="DB_NAME" size="20" value="<?php echo $DB_NAME ?>"/>
</fieldset>

<fieldset>
<label>Host name</label>
<input name="DB_HOST" placeholder="if needed" size="20" value="<?php echo $DB_HOST ?>"/>
<input name="DB_HOST" size="20" value="<?php echo $DB_HOST ?>"/>
<span class="hint">If needed</span>
</fieldset>

<fieldset>
<label>Port</label>
<input name="DB_PORT" type="number" placeholder="if needed, PgSQL only" size="20" value="<?php echo $DB_PORT ?>"/>
<input name="DB_PORT" type="number" size="20" value="<?php echo $DB_PORT ?>"/>
<span class="hint">Usually 3306 for MySQL or 5432 for PostgreSQL</span>
</fieldset>

<h2>Other settings</h2>
Expand Down Expand Up @@ -327,7 +339,7 @@ function make_self_url_path() {
<h2>Checking database</h2>

<?php
$link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE);
$link = db_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $DB_TYPE, $DB_PORT);

if (!$link) {
print_error("Unable to connect to database using specified parameters.");
Expand Down
5 changes: 5 additions & 0 deletions utility.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,8 @@ body.otp div.content {
display : inline-block;
width : auto;
}

span.hint {
font-size : 10px;
color : gray;
}

0 comments on commit bbffc43

Please sign in to comment.