/** * Override the default `doquote` method to better sanitize numeric values. * * @param ADOConnection $db * @param mixed $value * @param string $type * @return mixed */ public function doquote(&$db, $value, $type) { switch ($type) { case 'L': case 'I': case 'I1': case 'I2': case 'I4': case 'I8': case 'F': case 'N': if (!is_numeric($value)) { if (is_null($value)) { return null; } if ($value === true) { return 1; } if ($value === false) { return 0; } $db->outp_throw('Numeric field type "' . $type . '" requires numeric value.', 'DOQUOTE'); return 0; } default: return parent::doquote($db, $value, $type); } }
function _init_adodb_library(&$ci) { $db_var = false; $debug = false; $show_errors = true; $active_record = false; $db = NULL; if (!isset($dsn)) { // fallback to using the CI database file include APPPATH . 'config/database' . EXT; $group = 'default'; $dsn = $db[$group]['dbdriver'] . '://' . $db[$group]['username'] . ':' . $db[$group]['password'] . '@' . $db[$group]['hostname'] . '/' . $db[$group]['database']; } // Show Message Adodb Library PHP if ($show_errors) { require_once BASEPATH . 'packages/adodb5/adodb-errorhandler.inc' . EXT; } // $ci is by reference, refers back to global instance $ci->adodb =& ADONewConnection($dsn); // Use active record adodbx $ci->adodb->setFetchMode(ADODB_FETCH_ASSOC); if ($db_var) { // Also set the normal CI db variable $ci->db =& $ci->adodb; } if ($active_record) { require_once BASEPATH . 'packages/adodb5/adodb-active-record.inc' . EXT; ADOdb_Active_Record::SetDatabaseAdapter($ci->adodbx); } if ($debug) { $ci->adodb->debug = true; } }
public function __construct ($db_name=false,$keys=false) { if (!$keys) { $keys = array('ipFrom','ipTo'); } $this->unique_keys=$keys; parent::__construct(); }
public function __construct($tbl = null) { if ($tbl) { $db = Loader::db(); $this->_table = $tbl; parent::__construct($tbl); } }
public function save($data = null) { if ($data != null) { $this->setData($data); } parent::replace(); }
public function Load($where = null, $bindarr = false, $lock = false) { if (is_numeric($where)) { $where = $this->_prefix . "id = " . $where; } $ret = parent::Load($where, $bindarr, $lock); if ($ret && $this->has_meta()) { $this->load_meta($this); } return $ret; }
function connectToDatabase() { $dsn = 'mysqli://*****:*****@localhost/movies'; global $db; $db = ADONewConnection($dsn); if (!$db) { die("Failed to connect to database : " . $dsn); } ADOdb_Active_Record::SetDatabaseAdapter($db); ADOdb_Active_Record::ClassHasMany('Moviemains', 'Moviesupps', 'fk_movie'); return $db; }
public function crearconexion() { $db = NewADOConnection($this->gestor); if($db->NConnect($this->host,$this->user,$this->pass,$this->base)) { ADOdb_Active_Record::SetDatabaseAdapter($db); $ADODB_ASSOC_CASE = 0; return $db; } else { return false; } }
public function __construct($user, $password = '', $dbname = '', $host = '', $port = '', $sock = '', $retry = 3, $retry_int = 1) { $this->id = md5(uniqid('MTDatabase', true)); $retry_cnt = 0; while ((empty($this->conn) || !empty($this->conn) && !$this->conn->IsConnected()) && $retry_cnt++ < $retry) { try { $this->connect($user, $password, $dbname, $host, $port, $sock); } catch (Exception $e) { sleep($retry_int); } } if (empty($this->conn) || !empty($this->conn) && !$this->conn->IsConnected()) { throw new MTDBException($this->conn->ErrorMsg(), 0); } ADOdb_Active_Record::SetDatabaseAdapter($this->conn); # $this->conn->debug = true; }
define("LOOMP_USER_URI_NS", LOOMP_BASE_PATH . "/users/"); if (!strstr($_SERVER['REQUEST_URI'], 'install') && !strstr($_SERVER['REQUEST_URI'], 'error')) { try { // set database connection and retrieve the rdf model $logger->debug("Initializing RDF store"); $rdfStore = ModelFactory::getDbStore($configuration->loomp->db->type, $configuration->loomp->db->host, $configuration->loomp->db->name, $configuration->loomp->db->user, $configuration->loomp->db->pass); //die(LOOMP_MODEL_URI); $registry->rdfModel = $rdfStore->getModel(LOOMP_MODEL_URI); if ($registry->rdfModel === false) { throw new Exception("Failed to initialize RDF store."); } $logger->debug("Initializing Loomp API"); $registry->loompApi = new LoompApi(); // Active Record stuff require_once RDFAPI_INCLUDE_DIR . 'util/adodb/adodb-active-record.inc.php'; require_once APPLICATION_PATH . '/model/User.php'; require_once APPLICATION_PATH . '/model/Access.php'; ADOdb_Active_Record::SetDatabaseAdapter($rdfStore->getDbConn()); } catch (Exception $e) { $logger->err("Init error: " . $e->getMessage()); $logger->err($e->getTraceAsString()); $loomp_path = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . "/error/nosetup"; header("Location: " . $loomp_path); die; } } // CLEANUP - remove items from global scope // This will clear all our local boostrap variables from the global scope of // this script (and any scripts that called bootstrap). This will enforce // object retrieval through the Applications's Registry unset($frontController, $view, $configuration, $arsConfig, $registry, $logger, $translate);
<?php global $conf; global $global; error_reporting(E_ALL ^ E_NOTICE); define('APPROOT', realpath(dirname(__FILE__) . '/../') . '/'); $_SESSION['username'] = '******'; require_once APPROOT . 'conf/sysconf.php'; require_once APPROOT . '3rd/adodb5/adodb-active-record.inc.php'; require_once APPROOT . 'inc/lib_uuid.inc'; //load db handler require_once APPROOT . 'inc/handler_db.inc'; ADOdb_Active_Record::SetDatabaseAdapter($global['db']); //overide conf values from db require_once APPROOT . 'inc/handler_config.inc'; include_once APPROOT . 'inc/lib_entity_forms.inc'; //include_once APPROOT.'3rd/phpgacl/gacl.class.php'; include_once APPROOT . 'inc/lib_form_util.inc'; include_once APPROOT . 'inc/lib_files.inc'; include_once APPROOT . 'inc/security/lib_acl.inc'; include_once APPROOT . 'inc/security/handler_acl.inc'; include_once APPROOT . 'inc/lib_form.inc'; include_once APPROOT . 'inc/lib_form_util.inc'; require_once APPROOT . 'data/Browse.php'; require_once APPROOT . 'data/MtField.php'; require_once APPROOT . 'data/MtFieldWrapper.php'; require_once APPROOT . 'data/MtIndex.php'; require_once APPROOT . 'data/MtTerms.php'; $mtIndex = new MtIndex(); $index_terms = $mtIndex->Find(''); $options = array();
/** * Devuelve la conexion del nucleo * * @param String $dbx * @return ADOConnection */ public function getConexion($dbx = "default") { if ($this->conexion[$dbx] == null) { $ini = new Configuracion("bd.config"); $this->conexion[$dbx] = ADONewConnection($ini->get($dbx, "tipo")); $this->conexion[$dbx]->Connect($ini->get($dbx, "servidor"), $ini->get($dbx, "usuario"), $ini->get($dbx, "password"), $ini->get($dbx, "nombre")); $this->conexion[$dbx]->Execute("SET NAMES 'utf8'"); if ($dbx == "default") { ADOdb_Active_Record::SetDatabaseAdapter($this->conexion[$dbx]); } } return $this->conexion[$dbx]; }
* @librería que contiene la conexión a la Base de Datos * @fecha de creación: 16/05/2008 * @autor: Ing. Yesenia Moreno de Lang * ************************** * @fecha modificacion * @autor * @descripcion ***********************************************************************************/ include '../../base/librerias/php/adodb/adodb.inc.php'; include '../../base/librerias/php/adodb/adodb-exceptions.inc.php'; include '../../base/librerias/php/adodb/adodb-active-record.inc.php'; $conexionbd =& ADONewConnection($_SESSION['sigesp_gestor_apr']); $conexionbd->Connect($_SESSION['sigesp_servidor_apr'], $_SESSION['sigesp_usuario_apr'], $_SESSION['sigesp_clave_apr'], $_SESSION['sigesp_basedatos_apr']); if ($conexionbd != false) { $conexionbd->SetFetchMode(ADODB_FETCH_ASSOC); ADOdb_Active_Record::SetDatabaseAdapter($conexionbd); $ADODB_ASSOC_CASE = 0; $ADODB_FORCE_IGNORE = 0; } /*********************************************************************************** * @Función que se conecta a una base de datos según los parámetros * @parametros: * @retorno: * @fecha de creación: 20/10/2008 * @autor: Ing. Yesenia Moreno de Lang ************************************************************************************ * @fecha modificación: * @descripción: * @autor: ***********************************************************************************/ function conectarBD($servidor, $usuario, $clave, $basedatos, $gestor)
<?php require_once 'funcs.php'; $libraries = array('AR', 'Config', 'Validate', 'Html', 'Session', 'Response'); $models = array('Task'); $configuration_files = array('application' => 'inc/conf/application.php', 'database' => 'inc/conf/database.php', 'email' => 'inc/conf/email.php'); foreach ($libraries as $key => $value) { require_once 'inc/lib/utilities/' . $value . '.php'; } foreach ($models as $key => $value) { require_once 'inc/models/' . $value . '.php'; } Config::loads($configuration_files); // connect to database AR::$conn = connect(Config::read('database', 'username'), Config::read('database', 'password'), Config::read('database', 'server'), Config::read('database', 'database')); // AR::$conn->debug = 1; // turn on / off debug message ADOdb_Active_Record::SetDatabaseAdapter(AR::$conn); // set minimum length of password Validate::$min_length = 8; Session::init(); safe_post_data(); header("Content-Type: application/json; charset=utf-8");
function __construct() { parent::__construct('songs', array('recordid')); $this->belongsTo('artist', 'artistid'); }
public function __construct() { $db = Loader::db(); parent::__construct(); }
public function editarRegistro() { $this->usarScaffold(); //Conectarse a la base de datos if ($this->db == "") { $this->db = "default"; } $conexion = $this->nucleo->getConexion($this->db); $conexion->Execute("SET NAMES utf8"); //Primarias en $primarias //Demas campos en $campos $campos = $this->getCampos(); $registro = new ADOdb_Active_Record($this->modelo); $where = ""; foreach ($campos as $c) { if ($c["primaria"] == 1) { if ($where != "") { $where .= " AND "; } $where .= $c["nombre"] . "=" . $this->par['pri_' . $c["nombre"]]; } } $registro->Load($where); foreach ($campos as $c) { if ($c["auto"] == 1) { } elseif ($c["nombre"] == "password" || $c["nombre"] == "contrasena") { if ($this->par[$c["nombre"]] != "") { $registro->{$c}["nombre"] = md5($this->par[$c["nombre"]]); } } elseif ($c["nombre"] == "texto") { $registro->{$c}["nombre"] = stripslashes($this->par[$c["nombre"]]); } else { $registro->{$c}["nombre"] = $this->par[$c["nombre"]]; } } if ($registro->Save()) { $this->set("editado", "1"); $this->listado(); $this->set("vista", "listado"); } else { $this->set("editado", "0"); $this->agregar(); $this->set("vista", "agregar"); } }
if ($i != $cnt) { die("actual cnt is {$i}, cnt should be {$cnt}\n"); } else { echo "Count {$i} is correct<br>"; } $rs = $db->Execute("select bad from badder"); } catch (exception $e) { adodb_pr($e); echo "<h3>adodb_backtrace:</h3>\n"; $e = adodb_backtrace($e->gettrace()); } $rs = $db->Execute("select distinct id, firstname,lastname from adoxyz order by id"); echo "Result=\n", $rs, "</p>"; echo "<h3>Active Record</h3>"; include_once "../adodb-active-record.inc.php"; ADOdb_Active_Record::SetDatabaseAdapter($db); try { class City extends ADOdb_Active_Record { } $a = new City(); } catch (exception $e) { echo $e->getMessage(); } try { $a = new City(); echo "<p>Successfully created City()<br>"; #var_dump($a->GetPrimaryKeys()); $a->city = 'Kuala Lumpur'; $a->Save(); $a->Update();
public function __construct($appapikey, $appsecret, $adoConnectString) { $this->client = new Facebook($appapikey, $appsecret); $this->db = NewADOConnection($adoConnectString); ADOdb_Active_Record::SetDatabaseAdapter($this->db); }
/** * Returns the database object, or loads it if not yet created * <code> * <?php * $db = Loader::db(); * $db->query($sql); * </code> */ public function db($server = null, $username = null, $password = null, $database = null, $create = false, $autoconnect = true) { static $_dba; if ((!isset($_dba) || $create) && $autoconnect) { if ($server == null && defined('DB_SERVER')) { $dsn = DB_TYPE . '://' . DB_USERNAME . ':' . rawurlencode(DB_PASSWORD) . '@' . rawurlencode(DB_SERVER) . '/' . DB_DATABASE; } else { if ($server) { $dsn = DB_TYPE . '://' . $username . ':' . rawurlencode($password) . '@' . rawurlencode($server) . '/' . $database; } } if (isset($dsn) && $dsn) { $_dba = @NewADOConnection($dsn); if (is_object($_dba)) { $_dba->setFetchMode(ADODB_FETCH_ASSOC); if (DB_CHARSET != '') { $names = 'SET NAMES \'' . DB_CHARSET . '\''; if (DB_COLLATE != '') { $names .= ' COLLATE \'' . DB_COLLATE . '\''; } $_dba->Execute($names); } ADOdb_Active_Record::SetDatabaseAdapter($_dba); } else { if (defined('DB_SERVER')) { $v = View::getInstance(); $v->renderError(t('Unable to connect to database.'), t('A database error occurred while processing this request.')); } } } else { return false; } } return $_dba; }
} } $db = NewADOConnection('mysql://root@localhost/northwind?persist'); $db->debug = 1; ADOdb_Active_Record::SetDatabaseAdapter($db); $db->Execute("CREATE TEMPORARY TABLE `persons` (\r\n\t `id` int(10) unsigned NOT NULL auto_increment,\r\n\t `name_first` varchar(100) NOT NULL default '',\r\n\t `name_last` varchar(100) NOT NULL default '',\r\n\t `favorite_color` varchar(100) NOT NULL default '',\r\n\t PRIMARY KEY (`id`)\r\n\t ) ENGINE=MyISAM;\r\n\t "); $db->Execute("CREATE TEMPORARY TABLE `children` (\r\n\t `id` int(10) unsigned NOT NULL auto_increment,\r\n\t\t\t\t\t`person_id` int(10) unsigned NOT NULL,\r\n\t `name_first` varchar(100) NOT NULL default '',\r\n\t `name_last` varchar(100) NOT NULL default '',\r\n\t `favorite_pet` varchar(100) NOT NULL default '',\r\n\t PRIMARY KEY (`id`)\r\n\t ) ENGINE=MyISAM;\r\n\t "); class Person extends ADOdb_Active_Record { function ret($v) { return $v; } } $person = new Person(); ADOdb_Active_Record::$_quoteNames = '111'; echo "<p>Output of getAttributeNames: "; var_dump($person->getAttributeNames()); /** * Outputs the following: * array(4) { * [0]=> * string(2) "id" * [1]=> * string(9) "name_first" * [2]=> * string(8) "name_last" * [3]=> * string(13) "favorite_color" * } */
static function TableKeyBelongsTo($table, $tablePKey, $foreignRef, $foreignKey = false, $parentKey = '', $parentClass = 'ADODB_Active_Record') { if (!is_array($tablePKey)) { $tablePKey = array($tablePKey); } $ar = new ADOdb_Active_Record($table, $tablePKey); $ar->belongsTo($foreignRef, $foreignKey, $parentKey, $parentClass); }
<?php include_once Config::$home_lib . 'adodb5' . Config::$ds . 'adodb-active-record.inc.php'; ADOdb_Active_Record::SetDatabaseAdapter(App::$base->getADOdb()); class atable extends ADODB_Active_Record { function Save() { // Agregar el generador a la llave primaria en insercion // el generador debe llamarse GEN_(Campo PK) if (App::$base->driver == 'firebird') { $ids = $this->DB()->MetaPrimaryKeys($this->_table); // PK $id = count($ids) > 0 ? $ids[0] : ''; if (!$this->_saved && $id != '') { $id = strtolower($id); $gen = 'GEN_' . strtoupper($id); $this->{$id} = $this->DB()->GenID($gen); } } if (App::$base->driver == 'postgres' || App::$base->driver == 'postgres8') { $ids = $this->DB()->MetaPrimaryKeys($this->_table); // PK $id = count($ids) > 0 ? $ids[0] : ''; if (!$this->_saved && $id != '') { $gen = $this->_table . '_' . $id . '_seq'; //formato: tbl_nombretabla_id_campoid_seq $gen = strtolower($gen); $this->{$id} = $this->DB()->GenID($gen); } }