/**
 * Connect to the database
 */
function connectToDatabase( $cli, $script, $host, $user, $password, $database )
{
    if ( $user )
    {
        $db = eZDB::instance( "mysql",
                           array( 'server' => $host,
                                  'user' => $user,
                                  'password' => $password,
                                  'database' => $database ) );
    } else
    {
         $db = eZDB::instance();
         if ( $db->databaseName() != "mysql" )
         {
            $cli->error( 'This script can only show and convert mysql databases.' );
            $script->shutdown( 1 );
         }
    }

    if ( !is_object( $db ) )
    {
        $cli->error( 'Could not initialize database:' );
        $cli->error( '* No database handler was found for mysql' );
        $script->shutdown( 1 );
    }
    if ( !$db or !$db->isConnected() )
    {
        $cli->error( "Could not initialize database:" );
        $cli->error( "* Tried database " . eZTriedDatabaseString( $database, $host, $user, $password ) );

        // Fetch the database error message if there is one
        // It will give more feedback to the user what is wrong
        $msg = $db->errorMessage();
        if ( $msg )
        {
            $number = $db->errorNumber();
            if ( $number > 0 )
                $msg .= '(' . $number . ')';
            $cli->error( '* ' . $msg );
        }
        $script->shutdown( 1 );
    }

    return $db;
}
    $parameters = array('use_defaults' => false, 'server' => $host, 'user' => $user, 'password' => $password, 'database' => $database);
    if ($socket) {
        $parameters['socket'] = $socket;
    }
    if ($port) {
        $parameters['port'] = $port;
    }
    $db = eZDB::instance($type, $parameters, true);
    if (!is_object($db)) {
        $cli->error('Could not initialize database:');
        $cli->error('* No database handler was found for $type');
        $script->shutdown(1);
    }
    if (!$db or !$db->isConnected()) {
        $cli->error("Could not initialize database:");
        $cli->error("* Tried database " . eZTriedDatabaseString($database, $host, $user, $password, $socket));
        // Fetch the database error message if there is one
        // It will give more feedback to the user what is wrong
        $msg = $db->errorMessage();
        if ($msg) {
            $number = $db->errorNumber();
            if ($number > 0) {
                $msg .= '(' . $number . ')';
            }
            $cli->error('* ' . $msg);
        }
        $script->shutdown(1);
    }
    $dbSchema = eZDbSchema::instance($db);
}
if ($dbSchema === false) {