public static function singleton($connect = false) { if (!isset(self::$instance)) { self::$instance = new NDB($connect); } return self::$instance; }
function createFixtures($fixture_path, $fixture_table_names, $fixture_class_names) { $fixtures = array(); $connection =& NDB::connect(); $i = 0; foreach ($fixture_table_names as $table_name) { $fixtures[$table_name] = new Fixtures($connection, $table_name, $fixture_class_names[$i] ? $fixture_class_names[$i] : null, $fixture_path . $table_name); $i++; } // $this->all_loaded_fixtures = array_merge($this->all_loaded_fixtures, $fixtures_map); foreach (array_reverse($fixtures) as $f) { $f->deleteExistingFixtures(); } foreach ($fixtures as $f) { $f->insertFixtures(); } return count($fixtures) > 1 ? $fixtures : $fixtures[0]; }
function __construct() { $db =& NDB::connect(); $options['table'] = 'cms_auth'; $options['usernamecol'] = 'username'; $options['passwordcol'] = 'password'; $options['dsn'] =& $db; $options['db_fields'] = 'id, real_name, user_level, status'; $options['cryptType'] = 'md5'; $options['db_options'] = array(); parent::Auth('MDB2', $options, array($this, 'showLogin')); $this->setLoginCallback($this, 'loginCallBack'); $this->setLogoutCallback($this, 'loginCallBack'); if (!$this->checkAuth()) { $this->start(); } if (isset($_GET['logout']) && $_GET['logout']) { $this->logout(); $this->start(); exit; } }
<?php error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); require_once dirname(__FILE__) . '/../vendor/autoload.php'; require_once 'config/config.php'; date_default_timezone_set('America/Edmonton'); NDB::$db = 'nterchange_test'; $db = NDB::connect(NDB::serverDSN()); $db->loadModule('Manager'); $db->loadModule('Datatype'); echo '### dropping: ' . NDB::$db . "\n"; $db->exec(' DROP DATABASE IF EXISTS `' . NDB::$db . '`; '); echo '### creating: ' . NDB::$db . "\n"; $db->exec(' CREATE DATABASE `' . NDB::$db . '`; '); $db->setDatabase(NDB::$db); $schema_file = dirname(__FILE__) . '/fixtures/base_schema.sql'; $data_file = dirname(__FILE__) . 'fixtures/base_data.sql'; NDB::seed($db, $schema_file); NDB::seed($db, $data_file);
function getInsertSQL($table) { include_once 'n_db.php'; $db =& NDB::connect(); $tablefields = $db->tableInfo($table); $vals = $this->getSubmitValues(); $fields = ''; $values = ''; foreach ($tablefields as $tablefield) { $field_name = $tablefield['name']; $field_type = $tablefield['type']; $field_len = $tablefield['len']; if (isset($vals[$field_name])) { if ($fields != '') { $fields .= ','; } $fields .= $db->quoteIdentifier($field_name); if ($values != '') { $values .= ','; } $elem =& $this->getElement($field_name); $type = $elem->getType(); $val = $vals[$field_name]; $val = !get_magic_quotes_gpc() ? addslashes($val) : $val; switch ($type) { case 'submit': break; case 'header': break; case 'group': $tmp = ''; $group_type = $elem->getGroupType(); if ($group_type == 'radio') { foreach ($elem->_elements as $subelem) { $subval = $subelem->getValue(); if ($subval == $val) { if ($tmp != '') { $tmp .= ', '; } $tmp .= strip_tags($subelem->_text); break; } } } else { foreach ($elem->_elements as $subelem) { $type = $subelem->getType(); if ($type == 'checkbox') { if (isset($val[$subelem->getName()])) { if ($tmp != '') { $tmp .= ', '; } $tmp .= $subelem->_text ? $subelem->_text : $subelem->getValue(); } } else { if ($tmp != '') { $tmp .= ', '; } $tmp .= ($label ? ' ' : '') . ($subelem->_text ? $subelem->_text : $subelem->getValue()); } } } $values .= $db->quoteSmart($tmp); break; case 'select': $val = is_array($val) ? implode(', ', $val) : $val; $values .= $db->quoteSmart($val); break; case 'date': $vars = array('w', 'd', 'n', 'Y', 'h', 'H', 'i', 's', 'a', 'A'); $vars = array('D', 'l', 'd', 'M', 'm', 'F', 'Y', 'y', 'h', 'H', 'i', 's', 'a', 'A'); $tmp = ''; for ($i = 0, $length = strlen($elem->_options['format']); $i < $length; $i++) { $sign = $elem->_options['format'][$i]; $tmp .= in_array($sign, $vars) ? $val[$sign] : $sign; } if ($field_type == 'date') { $format = 'Y-m-d'; } else { if ($field_type == 'datetime') { $format = 'Y-m-d H:i:s'; } else { if ($field_type == 'time') { $format = 'H:i:s'; } else { $format = $elem->_options['format']; } } } $val = date($format, strtotime($tmp)); $values .= $db->quoteSmart($tmp); break; default: $values .= $db->quoteSmart($val); break; } } } if ($fields != '' && $values != '') { foreach ($tablefields as $tablefield) { if ($tablefield['name'] == 'ip' && !isset($vals[$tablefield['ip']])) { $fields .= ',' . $db->quoteIdentifier('ip'); $values .= ',' . $db->quoteSmart($_SERVER['REMOTE_ADDR']); } if ($tablefield['name'] == 'inserted' && !isset($vals[$tablefield['name']])) { $fields .= ',' . $db->quoteIdentifier('inserted'); $values .= ',NOW()'; } } } $sql = 'INSERT INTO ' . $db->quoteIdentifier($table) . " ({$fields}) VALUES ({$values})"; return $sql; }
/** * Find the id for a poll_value given the poll id and the string value */ function getValueId($poll_id, $value) { $db =& NDB::connect(); $res =& $db->query("SELECT `id` FROM poll_values WHERE `poll_id` = {$poll_id} AND `value` = '{$value}';"); if ($row = $res->fetchRow()) { return $row['id']; } return false; }
/** * deleteEverything - Delete all old versions of everything. Used just before * website launch or when somebody just wants to clean up. * NOTE: Not linked to from anywhere or really heavily tested. Use with caution. * * @return void **/ function deleteEverything($parameter) { if ($model =& $this->getDefaultModel()) { if ($model->find()) { while ($model->fetch()) { $arr = $model->toArray(); $content = unserialize($arr['version']); $success = $this->fileDelete($content, $arr['asset'], $arr['asset_id']); $this->deleteEmptyFolders($arr['asset'], $arr['asset_id']); $model->delete(); } // Let's empty out the entire table as well. $sql = 'TRUNCATE cms_nterchange_versions'; $db = NDB::connect(); $res = $db->query($sql); } else { NDebug::debug('There were no old versions of anything to delete.', N_DEBUGTYPE_INFO); } header('Location:/nterchange/'); } }
function __construct() { $db =& NDB::connect(); if (PEAR::isError($db)) { die('Can\'t connect to the db.'); } else { $this->_db =& $db; } $this->_loadConfig(); foreach ($this->_config as $field => $def) { $this->_fields[] = $field; $this->{$field} = null; } $this->table_name_prefix = defined('DB_TABLE_NAME_PREFIX') ? constant('DB_TABLE_NAME_PREFIX') : ''; $this->table_name_suffix = defined('DB_TABLE_NAME_SUFFIX') ? constant('DB_TABLE_NAME_SUFFIX') : ''; // load $this->_query with defaults // the defaults can be overridden in child classes $this->_buildQuery(); // save the original query before we can do any damage $this->_query_orig = $this->_query; parent::__construct(); }
function prepVals($vals, &$io) { if (is_object($io) && is_a($io, 'InputOutput')) { $table = $io->getObjectTable(); $db =& $io->db; } else { if (is_string($io)) { $table = $io; include_once 'n_db.php'; $db =& NDB::connect(); } } $table_info = $db->tableInfo($table); foreach ($vals as $field => $val) { $vals[$field] = ValueCast::prepVal($field, $val, $io, $table_info); } return $vals; }
<tr><td>APP_NAME</td><td><?php echo APP_NAME; ?> </td></tr> <tr><td>APP_DIR</td><td><?php echo APP_DIR; ?> </td></tr> <tr><td>BASE_DIR</td><td><?php echo BASE_DIR; ?> </td></tr> <tr> <?php $db = NDB::connect(); ?> <th colspan="2">Database</th> </tr> <tr> <?php $m = NModel::factory('cms_auth'); $user_count = $m->find(); ?> <td># of users</td><td><?php echo $user_count; ?> </td> </tr> </table> </body>
function seed_test_sample() { $seed_file = BASE_DIR . '/test/fixtures/test_sample.sql'; NDB::seed($this->db, $seed_file); }
public function __construct($id = false, $website_id = false) { $this->id = $id; $this->website_id = $website_id; $this->db = NDB::singleton(); }