Ticket #134 (accepted defect)

Opened 16 months ago

Last modified 14 months ago

install.php - mysql_connect failure - blank page - with fix

Reported by: jsellens Owned by: tdondich
Priority: major Milestone: 1.4
Component: Lilac Configurator Version: 1.0.2
Keywords: Cc:

Description

(Sent this to the lilac-users list April 18 2009 - hope the diff works without much trouble - thanks!)

On a new install of lilac-1.0.2, the install.php failed in the
database steps ("stage 2") and gave me an empty page.

I traced it down to a missing mysql_connect() function. The
install.php script calls @mysql_connect(), so the fatal error isn't
printed. (My PHP build was missing the --with-mysql configure
option.)

I would like to suggest that stage 1 in install.php check for the
mysql_connect() function.

In tracking this down, I made a few tweaks to install.php which
print the header before doing anything, and print a few progress
messages. I find this extra verbosity useful, but "your mileage
may vary".

I split print_header() into print_header() and a separate print_status()
function, so I could print the header, and then later print errors.
And I added a print_progress() function to give a play by play.

A unified diff of my changes to install.php is below for your
consideration.

Thanks - cheers!

John

--- install.php.orig 2009-04-17 16:16:40.000000000 -0400
+++ install.php 2009-04-18 03:03:50.000000000 -0400
@@ -83,6 +83,8 @@

}

+print_header("Installer");
+

if($stage == 2) {

$error = false;
if(!isset($_POSTmysqlRootUsername?)) {

@@ -96,6 +98,7 @@

$mysqlCreateUserDatabase = false;

}
else {

+ print_progress( "Checking paramters ..." );

$mysqlRootUsername = trim($_POSTmysqlRootUsername?);
$mysqlRootPassword = trim($_POSTmysqlRootPassword?);
$mysqlHostname = trim($_POSTmysqlHostname?);

@@ -130,6 +133,7 @@

// Okay, breathe, we're going to do the grunt of the work now.
// Check to see if we need to create the user and database
if($mysqlCreateUserDatabase) {

+ print_progress( "Creating database ..." );

// Attempt to connect as admin
$dbConn = @mysql_connect($mysqlHostname, $mysqlRootUsername, $mysqlRootPassword);
if(!$dbConn) {

@@ -168,6 +172,7 @@

}

}
if(!$error && $mysqlPopulate) {

+ print_progress( "Populating database ..." );

// Okay, we need to populate the database. Attempt to connect as our user.
$dbConn = @mysql_connect($mysqlHostname, $mysqlUsername, $mysqlPassword);
if(!$dbConn) {

@@ -201,19 +206,24 @@

}

}

}

- // Create PDO connection to perform upgrades
- try {
- $dbConn = new PDO("mysql:host=" . $mysqlHostname . ";dbname=" . $mysqlDatabase,
+$mysqlUsername, $mysqlPassword);
- } catch(PDOException $e) {
- $error = "Failed to connect to MySQL server with " . $mysqlUsername . " user:" .
+$e->getMessage();
+ if(!$error) {
+ print_progress( "Connecting to MySQL with PDO ..." );
+ // Create PDO connection to perform upgrades
+ try {
+ $dbConn = new PDO("mysql:host=" . $mysqlHostname . ";dbname=" . $mysqlDatabase,
+$mysqlUsername, $mysqlPassword);
+ } catch(PDOException $e) {
+ $error = "Failed to connect to MySQL server with " . $mysqlUsername . " user:" .
+$e->getMessage();
+ }

}
if(!$error) {

+ print_progress( "Doing upgrade ..." );

if(!perform_upgrade($dbConn)) {

$error = true;

}

}

if(!$error) {

+ print_progress( "Writing includes/lilac-conf.php ..." );

// Okay, write to the configuration file!
$conf = file_get_contents(dirname(FILE) . "/includes/lilac-conf.php.dist");
$conf = str_replace("%%DSN%%", "mysql:host=" . $mysqlHostname . ";dbname=" .

+$mysqlDatabase, $conf);
@@ -237,7 +247,8 @@

$warning = $noticeContents;

}

-print_header("Installer");
+// print_header("Installer");
+print_status();

if($stage == 1) {

$fatalErrors = false;

@@ -336,6 +347,25 @@

?>

<?php

+ // PHP mysql_connect() check - compiled with --with-mysql
+ $fail = !function_exists("mysql_connect");
+ ?>
+ <div class="<?php if($fail) echo "failure"; else echo "success";?>">
+ PHP MySQL Support
+ </div>
+ <?php
+ if($fail) {
+ ?>
+ <div class="error">
+ PHP's MySQL support is not available (no mysql_connect() function).
+ PHP needs to be built with the --with-mysql configure option.
+ </div>
+ <?php
+ }
+ if($fail) $fatalErrors = true;
+ ?>
+
+ <?php

// PDO MYSQL Extension Installed Check
$fail = !extension_loaded("pdo_mysql");
?>

@@ -1100,6 +1130,12 @@

</div>
<div id="main">
<?php

+}
+
+function print_status() {
+ global $success;
+ global $error;
+ global $warning;

if(!empty($success) !empty($error) !empty($warning)) {

?>
<script type="text/javascript">

@@ -1270,3 +1306,12 @@

return true;

}

+// progress reporting
+function print_progress( $s ) {
+ echo "<div class=\"notice\">\n";
+ echo "<strong>Progress:</strong> ";
+ echo "$s\n";
+ echo "</div>\n";
+}
+
+?>

Change History

Changed 14 months ago by tdondich

  • status changed from new to accepted
  • milestone set to 1.4

Sounds good. Will apply for 1.4

Note: See TracTickets for help on using tickets.