Example #1
0
/**
 * Open a connection to the database.
 * @param string $p_dsn Database connection string ( specified instead of other params)
 * @param string $p_hostname Database server hostname
 * @param string $p_username database server username
 * @param string $p_password database server password
 * @param string $p_database_name database name
 * @param string $p_db_schema Schema name (only used if database type is DB2)
 * @param bool $p_pconnect Use a Persistent connection to database
 * @return bool indicating if the connection was successful
 */
function db_connect($p_dsn, $p_hostname = null, $p_username = null, $p_password = null, $p_database_name = null, $p_db_schema = null, $p_pconnect = false)
{
    global $g_db_connected, $g_db;
    $t_db_type = config_get_global('db_type');
    if (!db_check_database_support($t_db_type)) {
        error_parameters(0, 'PHP Support for database is not enabled');
        trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
    }
    if ($p_dsn === false) {
        $g_db = ADONewConnection($t_db_type);
        if ($p_pconnect) {
            $t_result = $g_db->PConnect($p_hostname, $p_username, $p_password, $p_database_name);
        } else {
            $t_result = $g_db->Connect($p_hostname, $p_username, $p_password, $p_database_name);
        }
    } else {
        $g_db = ADONewConnection($p_dsn);
        $t_result = $g_db->IsConnected();
    }
    if ($t_result) {
        // For MySQL, the charset for the connection needs to be specified.
        if (db_is_mysql()) {
            /** @todo Is there a way to translate any charset name to MySQL format? e.g. remote the dashes? */
            /** @todo Is this needed for other databases? */
            db_query_bound('SET NAMES UTF8');
        } else {
            if (db_is_db2() && $p_db_schema !== null && !is_blank($p_db_schema)) {
                $t_result2 = db_query_bound('set schema ' . $p_db_schema);
                if ($t_result2 === false) {
                    db_error();
                    trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
                    return false;
                }
            }
        }
    } else {
        db_error();
        trigger_error(ERROR_DB_CONNECT_FAILED, ERROR);
        return false;
    }
    $g_db_connected = true;
    return true;
}
Example #2
0
$t_database_dsn = config_get_global( 'dsn' );
check_print_info_row(
	'Using a custom <a href="http://en.wikipedia.org/wiki/Database_Source_Name">Database Source Name</a> (DSN) for connecting to the database',
	$t_database_dsn ? 'Yes' : 'No'
);

$t_database_type = config_get_global( 'db_type' );
check_print_info_row(
	'Database type',
	htmlentities( $t_database_type )
);

check_print_test_row(
	'Database type is supported by the version of PHP installed on this server',
	db_check_database_support( $t_database_type ),
	array( false => 'The current database type is set to ' . htmlentities( $t_database_type ) . '. The version of PHP installed on this server does not have support for this database type.' )
);

if ( db_is_mssql() ) {

	$t_mssql_textsize = ini_get_number( 'mssql.textsize' );
	check_print_info_row(
		'php.ini directive: mssql.textsize',
		htmlentities( $t_mssql_textsize )
	);

	check_print_test_warn_row(
		'mssql.textsize php.ini directive is set to -1',
		$t_mssql_textsize == -1,
		array( false => 'The value of the mssql.textsize directive is currently ' . htmlentities( $t_mssql_textsize ) . '. You should set this value to -1 to prevent large text fields being truncated upon being read from the database.' )
Example #3
0
<?php 
    if (false == $g_failed) {
        $t_install_state++;
    }
}
# end install_state == 0
# got database information, check and install
if (2 == $t_install_state) {
    ?>

<table width="100%" cellpadding="10" cellspacing="1">

<!-- Checking DB support-->
<?php 
    print_test('Setting Database Type', '' !== $f_db_type, true, 'database type is blank?');
    print_test('Checking PHP support for database type', db_check_database_support($f_db_type), true, 'database is not supported by PHP. Check that it has been compiled into your server.');
    # ADOdb library version check
    # PostgreSQL, Oracle and MSSQL require at least 5.19. MySQL should be fine
    # with 5.10 but to simplify we align to the requirement of the others.
    $t_adodb_version = substr($ADODB_vers, 1, strpos($ADODB_vers, ' ') - 1);
    print_test('Checking ADOdb Library version is at least ' . DB_MIN_VERSION_ADODB, version_compare($t_adodb_version, DB_MIN_VERSION_ADODB, '>='), true, 'Current version: ' . $ADODB_vers);
    print_test('Setting Database Hostname', '' !== $f_hostname, true, 'host name is blank');
    print_test('Setting Database Username', '' !== $f_db_username, true, 'database username is blank');
    print_test('Setting Database Password', '' !== $f_db_password, false, 'database password is blank');
    print_test('Setting Database Name', '' !== $f_database_name || $f_db_type == 'oci8', true, 'database name is blank');
    if ($f_db_type == 'db2') {
        print_test('Setting Database Schema', !is_blank($f_db_schema), true, 'must have a schema name for AS400 in the form of DBNAME/SCHEMA');
    }
    ?>
<tr>
	<td bgcolor="#ffffff">
    if (preg_match('/^[Vv]([0-9\\.]+)/', $ADODB_vers, $t_matches) == 1) {
        $t_adodb_version_check_ok = version_compare($t_matches[1], DB_MIN_VERSION_ADODB, '>=');
        $t_adodb_version_info = 'ADOdb version ' . htmlentities($t_matches[1]) . ' was found.';
    }
    # Making sure we're not using the ADOdb extension (see #14552)
    check_print_test_row('Checking use of the <a href="http://adodb.sourceforge.net/#extension">ADOdb extension</a>', !extension_loaded('ADOdb'), 'The ADOdb extension is not supported and must be disabled');
}
check_print_test_row('Version of <a href="http://en.wikipedia.org/wiki/ADOdb">ADOdb</a> available is at least ' . DB_MIN_VERSION_ADODB, $t_adodb_version_check_ok, $t_adodb_version_info);
if (!$t_adodb_version_check_ok) {
    return;
}
$t_database_dsn = config_get_global('dsn');
check_print_info_row('Using a custom <a href="http://en.wikipedia.org/wiki/Database_Source_Name">Database Source Name</a> (DSN) for connecting to the database', $t_database_dsn ? 'Yes' : 'No');
$t_database_type = config_get_global('db_type');
check_print_info_row('Database type', htmlentities($t_database_type));
check_print_test_row('Database type is supported by the version of PHP installed on this server', db_check_database_support($t_database_type), array(false => 'The current database type is set to ' . htmlentities($t_database_type) . '. The version of PHP installed on this server does not have support for this database type.'));
if (db_is_mysql()) {
    check_print_test_warn_row('PHP support for MySQL driver', 'mysql' != $t_database_type, array(false => "'mysql' driver is deprecated as of PHP 5.5.0, please use 'mysqli' instead"));
}
if (db_is_mssql()) {
    check_print_test_warn_row('PHP support for Microsoft SQL Server driver', 'mssql' != $t_database_type, array(false => "'mssql' driver is no longer supported in PHP >= 5.3, please use 'mssqlnative' instead"));
    $t_mssql_textsize = ini_get_number('mssql.textsize');
    check_print_info_row('php.ini directive: mssql.textsize', htmlentities($t_mssql_textsize));
    check_print_test_warn_row('mssql.textsize php.ini directive is set to -1', $t_mssql_textsize == -1, array(false => 'The value of the mssql.textsize directive is currently ' . htmlentities($t_mssql_textsize) . '. You should set this value to -1 to prevent large text fields being truncated upon being read from the database.'));
    $t_mssql_textlimit = ini_get_number('mssql.textlimit');
    check_print_info_row('php.ini directive: mssql.textlimit', htmlentities($t_mssql_textlimit));
    check_print_test_warn_row('mssql.textlimit php.ini directive is set to -1', $t_mssql_textlimit == -1, array(false => 'The value of the mssql.textlimit directive is currently ' . htmlentities($t_mssql_textlimit) . '. You should set this value to -1 to prevent large text fields being truncated upon being read from the database.'));
}
$t_database_hostname = config_get_global('hostname');
check_print_info_row('Database hostname', htmlentities($t_database_hostname));
$t_database_username = config_get_global('db_username');