| // +---------------------------------------------------------------------------+ function canConnectToDbServer() { $aFormValues = $_SESSION['_installationWizard_container']['values']['page4']; $socket = (isset($aFormValues['dbProtocol']['protocol']) && $aFormValues['dbProtocol']['protocol'] == 'unix' && !empty($aFormValues['socket'])) ? '(' . $aFormValues['socket'] . ')' : ''; $protocol = isset($aFormValues['dbProtocol']['protocol']) ? $aFormValues['dbProtocol']['protocol'] . $socket : ''; $host = empty($aFormValues['socket']) ? '+' . $aFormValues['host'] : ''; $port = (!empty($aFormValues['dbPort']['port']) && isset($aFormValues['dbProtocol']['protocol']) && ($aFormValues['dbProtocol']['protocol'] == 'tcp')) ? ':' . $aFormValues['dbPort']['port'] : ''; $dbName = (!empty($aFormValues['dbName']) && ($aFormValues['dbName'] != 'not required for MySQL login')) ? '/'.$aFormValues['dbName'] : ''; $dsn = $aFormValues['dbType']['type'] . '://' . $aFormValues['databaseUser'] . ':' . $aFormValues['databaseUserPass'] . '@' . $protocol . $host . $port . $dbName; // attempt to get db connection $dbh = & SGL_DB::singleton($dsn); if (PEAR::isError($dbh)) { SGL_Install_Common::errorPush($dbh); return false; } else { // detect and store DB info if (preg_match("/mysqli/", $dbh->phptype)) { $mysqlVersion = mysqli_get_server_info($dbh->connection); } elseif (preg_match("/mysql/", $dbh->phptype)) { $mysqlVersion = mysql_get_server_info(); } $aEnvData = unserialize(file_get_contents(SGL_VAR_DIR . '/env.php')); $aEnvData['db_info'] = array( 'dbDriver' => $dbh->phptype, 'version' => isset($mysqlVersion) ? $mysqlVersion : '', ); $serialized = serialize($aEnvData); @file_put_contents(SGL_VAR_DIR . '/env.php', $serialized); return true; } } /** * @package Install */ class WizardTestDbConnection extends HTML_QuickForm_Page { function buildForm() { $this->_formBuilt = true; $this->addElement('header', null, 'Test DB Connection: page 4 of 6'); // FIXME: use env.php info to supply sensible defaults $this->setDefaults(array( 'host' => 'localhost', 'dbProtocol' => array('protocol' => 'unix'), 'dbType' => array('type' => 'mysql_SGL'), 'dbPortChoices' => array('portOption' => 3306), 'dbPort' => array('port' => 3306), 'dbName' => 'not required for MySQL login', 'dbSequencesInOneTable' => array('dbSequences' => 1), )); $this->setDefaults(SGL_Install_Common::overrideDefaultInstallSettings()); // type $radio[] = &$this->createElement('radio', 'type', 'Database type: ', "mysql_SGL", 'mysql_SGL', 'onClick="toggleDbNameForLogin(false);toggleDefaultStorageEngine(true)"'); $radio[] = &$this->createElement('radio', 'type', 'Database type: ', "mysqli_SGL", 'mysqli_SGL', 'onClick="toggleDbNameForLogin(false);toggleDefaultStorageEngine(true)"'); $radio[] = &$this->createElement('radio', 'type', '', "mysql", 'mysql', 'onClick="toggleDbNameForLogin(false);toggleDefaultStorageEngine(true);"'); $radio[] = &$this->createElement('radio', 'type', '', "mysqli", 'mysqli', 'onClick="toggleDbNameForLogin(false);toggleDefaultStorageEngine(true);"'); if (SGL_MINIMAL_INSTALL == false) { $radio[] = &$this->createElement('radio', 'type', '', "postgres", 'pgsql', 'onClick="toggleDbNameForLogin(true);toggleDefaultStorageEngine(false);"'); //$radio[] = &$this->createElement('radio', 'type', '', "oci8", 'oci8_SGL', // 'onClick="toggleDbNameForLogin(true);toggleDefaultStorageEngine(false);"'); } $this->addGroup($radio, 'dbType', 'Database type:', '
'); $this->addGroupRule('dbType', 'Please specify a db type', 'required'); unset($radio); $radio[] = &$this->createElement('radio', 'dbSequences', '', 'yes', 1); $radio[] = &$this->createElement('radio', 'dbSequences', '', 'no', 0); $this->addGroup($radio, 'dbSequencesInOneTable', 'Store sequences in one table:', '
'); $aMysqlEngines = array( '0' => 'server default', 'myisam' => 'MyISAM', 'innodb' => 'InnoDB', 'ndbcluster' => 'MySQL Cluster' ); $this->addElement('select', 'dbMysqlDefaultStorageEngine', 'Default storage engine:', $aMysqlEngines, 'id="defaultStorageEngine"'); // host $this->addElement('text', 'host', 'Host: '); $this->addRule('host', 'Please specify the hostname', 'required'); // socket $this->addElement('text', 'socket', 'Socket: '); // protocol unset($radio); $radio[] = &$this->createElement('radio', 'protocol', 'Protocol: ',"unix (fine for localhost connections)", 'unix'); $radio[] = &$this->createElement('radio', 'protocol', '',"tcp", 'tcp'); $this->addGroup($radio, 'dbProtocol', 'Protocol:', '
'); $this->addGroupRule('dbProtocol', 'Please specify a db protocol', 'required'); // port unset($radio); $radio[] = &$this->createElement('radio', 'portOption', 'TCP port: ',"3306 (MySQL default)", 3306, 'onClick="copyValueToPortElement(this);"'); if (SGL_MINIMAL_INSTALL == false) { $radio[] = &$this->createElement('radio', 'portOption', '',"5432 (Postgres default)", 5432, 'onClick="copyValueToPortElement(this);"'); $radio[] = &$this->createElement('radio', 'portOption', '',"1521 (Oracle default)", 1521, 'onClick="copyValueToPortElement(this);"'); } $this->addGroup($radio, 'dbPortChoices', 'TCP port:', '
'); $this->addElement('text', 'dbPort[port]', '', 'id="targetPortElement"'); #$this->addRule('dbPort[port]', 'Please specify a db port', 'required'); // credentials $this->addElement('text', 'databaseUser', 'Database username: '); $this->addElement('password', 'databaseUserPass', 'Database password: '); $this->addElement('text', 'dbName', 'Database name: ', array( 'id' => 'dbLoginNameElement', 'size'=> 25)); $this->addRule('databaseUser', 'Please specify the db username', 'required'); // test db connect $this->registerRule('canConnectToDbServer','function','canConnectToDbServer'); $this->addRule('databaseUser', 'cannot connect to the db, please check all credentials', 'canConnectToDbServer'); // submit $prevnext[] =& $this->createElement('submit', $this->getButtonName('back'), '<< Back'); $prevnext[] =& $this->createElement('submit', $this->getButtonName('next'), 'Next >>'); $this->addGroup($prevnext, null, '', ' ', false); $this->setDefaultAction('next'); } } ?>