Skip to content

Commit

Permalink
add a check for existence of PHP mysql database driver
Browse files Browse the repository at this point in the history
  • Loading branch information
lieryan committed Apr 6, 2012
1 parent b266b3b commit c05b40e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions installer/controllers/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ public function validate_mysql_db_name($db_name)
*/
public function test_db_connection()
{
if ( ! $this->installer_lib->mysql_available())
{
$this->form_validation->set_message('test_db_connection', lang('db_missing'));
return false;
}
if ( ! $this->installer_lib->test_db_connection())
{
$this->form_validation->set_message('test_db_connection', lang('db_failure') . mysql_error());
Expand Down
3 changes: 2 additions & 1 deletion installer/language/english/step_1_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$lang['db_settings'] = 'Database Settings';
$lang['db_text'] = 'PyroCMS requires a database (MySQL) to store all of your content and settings, so the first thing we need to do is check if the database connection details are ok. If you do not understand what you are being asked to enter please ask your web hosting provider or server administrator for the details.';
$lang['db_missing'] = 'The mysql database driver for PHP were not found, installation cannot continue. Ask your host or server administrator to install it.';

$lang['server'] = 'MySQL Hostname';
$lang['username'] = 'MySQL Username';
Expand All @@ -23,4 +24,4 @@
$lang['db_success'] = 'The database settings are tested and working fine.';
$lang['db_failure'] = 'Problem connecting to the database: ';

/* End of file step_1_lang.php */
/* End of file step_1_lang.php */
17 changes: 13 additions & 4 deletions installer/libraries/installer_lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ function php_acceptable($version = NULL)
}


/**
* @return bool
*
* Function to check that MySQL and its PHP module is installed properly
*/
public function mysql_available()
{
return function_exists('mysql_connect');
}
/**
* @param string $type The MySQL type, client or server
* @return string The MySQL version of either the server or the client
Expand Down Expand Up @@ -200,7 +209,7 @@ public function test_db_connection()
$password = $this->ci->session->userdata('password');
$port = $this->ci->session->userdata('port');

return @mysql_connect("$hostname:$port", $username, $password);
return $this->mysql_available() && @mysql_connect("$hostname:$port", $username, $password);
}

/**
Expand Down Expand Up @@ -415,9 +424,9 @@ function write_config_file()
}

public function curl_enabled()
{
{
return (bool) function_exists('curl_init');
}
}
}

/* End of file installer_lib.php */
/* End of file installer_lib.php */
5 changes: 4 additions & 1 deletion installer/views/step_1.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

<section class="item">
<p>{db_text}</p>
<?php if ( !$this->installer_lib->mysql_available() ): ?>
<p class="result fail">{db_missing}</p>
<?php endif; ?>

<div class="input">
<label for="hostname">{server}</label>
Expand Down Expand Up @@ -86,4 +89,4 @@
<input id="next_step" type="submit" id="submit" value="{step2}" class="btn orange" />
</section>

<?php echo form_close(); ?>
<?php echo form_close(); ?>

0 comments on commit c05b40e

Please sign in to comment.