Example #1
0
function dbConnect()
{
    $host = "**********";
    $user = "******";
    $pwd = "*********";
    $database = "sduncan";
    include "../adodb5/adodb.inc.php";
    $db = newADOConnection('mysqli');
    $db->Connect($host, $user, $pwd, $database);
    return $db;
}
Example #2
0
 *	queXF is free software; you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation; either version 2 of the License, or
 *	(at your option) any later version.
 *	
 *	queXF is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 *	
 *	You should have received a copy of the GNU General Public License
 *	along with queXF; if not, write to the Free Software
 *	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
include_once dirname(__FILE__) . '/config.inc.php';
include_once dirname(__FILE__) . '/lang.inc.php';
/* DB FILE */
if (!(include_once ADODB_DIR . 'adodb.inc.php')) {
    print "<p>" . T_("ERROR: Please modify config.inc.php to point to your ADODb installation") . "</p>";
}
//if (!(include_once(ADODB_DIR . 'session/adodb-session2.php')))
//{
//	print "<p>" . T_("ERROR: Please modify config.inc.php to point to your ADODb installation") . "</p>";
//}
//global database variable
$db = newADOConnection(DB_TYPE);
$db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
//store session in database (see sessions2 table)
//ADOdb_Session::config(DB_TYPE, DB_HOST, DB_USER, DB_PASS, DB_NAME,$options=false);
 /**
  * Create a new database
  *
  * @param string $adminname Name of database administrator user (optional)
  * @param string $adminpasswd Password for the database administrator user (optional)
  * @returns bool was the new db created?
  * @throws Exception invalid db-name
  */
 public function create_database($adminname = '', $adminpasswd = '')
 {
     //THIS IS CALLED BY SETUP DON'T KILL IT!
     if ($this->adodb && $this->adodb->IsConnected()) {
         $this->adodb->Disconnect();
         //close the dead connection to be safe
     }
     $this->adodb = newADOConnection($GLOBALS['phpgw_info']['server']['db_type']);
     $this->adodb->NConnect($this->Host, $adminname, $adminpasswd);
     if (!$this->adodb || $this->adodb->IsConnected()) {
         echo 'Connection FAILED<br />';
         return False;
     }
     if (!preg_match('/^[a-z0-9_]+$/i', $this->Database)) {
         throw new Exception(lang('ERROR: the name %1 contains illegal charackter for cross platform db-support', $this->Database));
     }
     //create the db
     $this->adodb->Execute("CREATE DATABASE {$this->Database}");
     //Grant rights on the db
     switch ($GLOBALS['phpgw_info']['server']['db_type']) {
         case 'mysql':
             $this->adodb->Execute("GRANT ALL ON {$this->Database}.*" . " TO {$this->User}@{$_SERVER['SERVER_NAME']}" . " IDENTIFIED BY '{$this->Password}'");
             break;
         default:
             //do nothing
     }
     $this->adodb->Disconnect();
     return True;
 }
Example #4
0
/**
 * Return an option list of each queXS questionnaire and sample associated with
 * this Limesurvey instrument
 * 
 * @param int $lime_sid The limesurvey sid
 * @param string $seleced The selected response, if any
 * 
 * @return string A list of options for an XHTML select box
 * @author Adam Zammit <*****@*****.**>
 * @since  2011-09-07
 */
function get_questionnaire_sample_list($lime_sid, $selected = "")
{
    $db = newADOConnection(DB_TYPE);
    $db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    $db->SetFetchMode(ADODB_FETCH_ASSOC);
    $return = "";
    $sql = "(SELECT q.questionnaire_id, q.description AS qdes, 0 as sample_import_id, '" . TQ_("All samples") . "' AS sdes\r\n\t\tFROM questionnaire AS q\r\n\t\tWHERE q.lime_sid = '{$lime_sid}')\r\n\t\tUNION\r\n\t\t(SELECT q.questionnaire_id, q.description AS qdes, qs.sample_import_id, s.description AS sdes\r\n\t\tFROM questionnaire AS q, questionnaire_sample AS qs, sample_import AS s\r\n\t\tWHERE q.lime_sid = '{$lime_sid}'\r\n\t\tAND q.questionnaire_id = qs.questionnaire_id\r\n\t\tAND s.sample_import_id = qs.sample_import_id)\r\n\t\tORDER BY questionnaire_id ASC, sample_import_id ASC";
    $rs = $db->GetAll($sql);
    if (empty($rs)) {
        return false;
    }
    foreach ($rs as $r) {
        $s = "";
        if (array($r['questionnaire_id'], $r['sample_import_id']) == $selected) {
            $s = "selected='selected'";
        }
        $return .= "<option {$s} value='{$r['questionnaire_id']}:{$r['sample_import_id']}'>{$r['qdes']} - {$r['sdes']}</option>";
    }
    return $return;
}
 /**
  * Legacy supprt for quyering metadata from database
  *
  */
 protected function _connect_adodb()
 {
     require_once PHPGW_API_INC . '/adodb/adodb.inc.php';
     $this->adodb = newADOConnection($this->Type);
     $this->adodb->SetFetchMode(ADODB_FETCH_BOTH);
     return @$this->adodb->connect($this->Host, $this->User, $this->Password, $this->Database);
 }
Example #6
0
 function dbReconnect()
 {
     global $db;
     if (!$db->IsConnected()) {
         //keep reconnecting to the db so it doesn't time out
         $db = newADOConnection(DB_TYPE);
         $db->Connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
         $db->SetFetchMode(ADODB_FETCH_ASSOC);
     }
 }