mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-29 04:39:56 +03:00
feature 1255: add pwg_select_db function.
git-svn-id: http://piwigo.org/svn/trunk@5230 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
62ce6a7f15
commit
54c9ceb0f4
8 changed files with 47 additions and 19 deletions
|
@ -105,8 +105,8 @@ include( PHPWG_ROOT_PATH .'include/template.class.php');
|
||||||
|
|
||||||
// Database connection
|
// Database connection
|
||||||
$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
|
$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
|
||||||
$conf['db_password'], $conf['db_base'])
|
$conf['db_password'], $conf['db_base']);
|
||||||
or my_error('pwg_db_connect', true);
|
pwg_select_db($conf['db_base'], $pwg_db_link);
|
||||||
|
|
||||||
pwg_db_check_charset();
|
pwg_db_check_charset();
|
||||||
|
|
||||||
|
|
|
@ -32,14 +32,18 @@ define('DB_RANDOM_FUNCTION', 'RAND');
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function pwg_db_connect($host, $user, $password, $database)
|
function pwg_db_connect($host, $user, $password, $database=null, $die=true)
|
||||||
{
|
{
|
||||||
$link = mysql_connect($host, $user, $password) or my_error('mysql_connect', false);
|
$link = @mysql_connect($host, $user, $password) or my_error('mysql_connect', $die);
|
||||||
mysql_select_db($database, $link) or my_error('mysql_select_db', false);
|
|
||||||
|
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pwg_select_db($database, $link, $die=true)
|
||||||
|
{
|
||||||
|
return @mysql_select_db($database, $link) or my_error('mysql_select_db', $die);
|
||||||
|
}
|
||||||
|
|
||||||
function pwg_db_check_charset()
|
function pwg_db_check_charset()
|
||||||
{
|
{
|
||||||
defined('PWG_CHARSET') and defined('DB_CHARSET')
|
defined('PWG_CHARSET') and defined('DB_CHARSET')
|
||||||
|
|
|
@ -33,7 +33,7 @@ define('DB_RANDOM_FUNCTION', 'RANDOM');
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function pwg_db_connect($host, $user, $password, $database)
|
function pwg_db_connect($host, $user, $password, $database, $die=true)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ function pwg_db_connect($host, $user, $password, $database)
|
||||||
try {
|
try {
|
||||||
$link = new PDO($db_file);
|
$link = new PDO($db_file);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
my_error('sqlite::open', true);
|
my_error('sqlite::open', $die);
|
||||||
}
|
}
|
||||||
|
|
||||||
$link->sqliteCreateFunction('now', 'pwg_now', 0);
|
$link->sqliteCreateFunction('now', 'pwg_now', 0);
|
||||||
|
@ -56,6 +56,11 @@ function pwg_db_connect($host, $user, $password, $database)
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pwg_select_db($database=null, $link=null, $die=null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function pwg_db_check_charset()
|
function pwg_db_check_charset()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -33,7 +33,7 @@ define('DB_RANDOM_FUNCTION', 'RANDOM');
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function pwg_db_connect($host, $user, $password, $database)
|
function pwg_db_connect($host, $user, $password, $database, $die=true)
|
||||||
{
|
{
|
||||||
$connection_string = '';
|
$connection_string = '';
|
||||||
if (strpos($host,':') !== false)
|
if (strpos($host,':') !== false)
|
||||||
|
@ -49,11 +49,16 @@ function pwg_db_connect($host, $user, $password, $database)
|
||||||
$user,
|
$user,
|
||||||
$password,
|
$password,
|
||||||
$database);
|
$database);
|
||||||
$link = pg_connect($connection_string) or my_error('pg_connect', false);
|
$link = pg_connect($connection_string) or my_error('pg_connect', $die);
|
||||||
|
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pwg_select_db($database=null, $link=null, $die=null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function pwg_db_check_charset()
|
function pwg_db_check_charset()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -33,7 +33,7 @@ define('DB_RANDOM_FUNCTION', 'RANDOM');
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function pwg_db_connect($host, $user, $password, $database)
|
function pwg_db_connect($host, $user, $password, $database, $die=true)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ function pwg_db_connect($host, $user, $password, $database)
|
||||||
try {
|
try {
|
||||||
$link = new SQLite3($db_file, $sqlite_open_mode);
|
$link = new SQLite3($db_file, $sqlite_open_mode);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
my_error('sqlite::open', true);
|
my_error('sqlite::open', $die);
|
||||||
}
|
}
|
||||||
|
|
||||||
$link->createFunction('now', 'pwg_now', 0);
|
$link->createFunction('now', 'pwg_now', 0);
|
||||||
|
@ -64,6 +64,11 @@ function pwg_db_connect($host, $user, $password, $database)
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pwg_select_db($database=null, $link=null, $die=null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function pwg_db_check_charset()
|
function pwg_db_check_charset()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|
17
install.php
17
install.php
|
@ -227,11 +227,20 @@ if (!isset($step))
|
||||||
//---------------------------------------------------------------- form analyze
|
//---------------------------------------------------------------- form analyze
|
||||||
if ( isset( $_POST['install'] ))
|
if ( isset( $_POST['install'] ))
|
||||||
{
|
{
|
||||||
|
ob_start();
|
||||||
if (($pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'],
|
if (($pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'],
|
||||||
$_POST['dbpasswd'], $_POST['dbname']))!==false)
|
$_POST['dbpasswd'], $_POST['dbname'], false))!==false)
|
||||||
{
|
{
|
||||||
|
if (pwg_select_db($_POST['dbname'], $pwg_db_link, false)!==false)
|
||||||
array_push( $infos, l10n('Parameters are correct') );
|
{
|
||||||
|
array_push( $infos, l10n('Parameters are correct') );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
array_push( $errors,
|
||||||
|
l10n('Connection to server succeed, but it was impossible to connect to database') );
|
||||||
|
}
|
||||||
|
ob_end_clean();
|
||||||
|
|
||||||
$required_version = constant('REQUIRED_'.strtoupper($dblayer).'_VERSION');
|
$required_version = constant('REQUIRED_'.strtoupper($dblayer).'_VERSION');
|
||||||
if ( version_compare(pwg_get_db_version(), $required_version, '>=') )
|
if ( version_compare(pwg_get_db_version(), $required_version, '>=') )
|
||||||
|
@ -261,8 +270,8 @@ if ( isset( $_POST['install'] ))
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
array_push( $errors, l10n('Can\'t connect to server') );
|
array_push( $errors, l10n('Can\'t connect to server') );
|
||||||
|
ob_end_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
$webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name ));
|
$webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name ));
|
||||||
if ( empty($webmaster))
|
if ( empty($webmaster))
|
||||||
array_push( $errors, l10n('enter a login for webmaster') );
|
array_push( $errors, l10n('enter a login for webmaster') );
|
||||||
|
|
|
@ -52,8 +52,8 @@ define('PREFIX_TABLE', $prefixeTable);
|
||||||
|
|
||||||
// Database connection
|
// Database connection
|
||||||
$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
|
$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
|
||||||
$conf['db_password'], $conf['db_base'])
|
$conf['db_password'], $conf['db_base']);
|
||||||
or my_error('pwg_db_connect', true);
|
pwg_select_db($conf['db_base'], $pwg_db_link);
|
||||||
|
|
||||||
pwg_db_check_charset();
|
pwg_db_check_charset();
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,8 @@ define('UPGRADES_PATH', PHPWG_ROOT_PATH.'install/db');
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
||||||
$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
|
$pwg_db_link = pwg_db_connect($conf['db_host'], $conf['db_user'],
|
||||||
$conf['db_password'], $conf['db_base'])
|
$conf['db_password'], $conf['db_base']);
|
||||||
or my_error('pwg_db_connect', true);
|
pwg_select_db($conf['db_base'], $pwg_db_link);
|
||||||
|
|
||||||
pwg_db_check_charset();
|
pwg_db_check_charset();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue