public static function init($host, $user, $pw, $db) { self::$connection = DBConnection::getInstance("main"); if (!self::$connection->isOpen()) { self::$connection->init($host, $user, $pw, $db); } }
function __construct($link = null) { global $simplepo_config; $this->sql = ""; $this->table_prefix = $simplepo_config['table_prefix']; if (!$link) { $this->link = DBConnection::getInstance(); } }
/** * Standard interface for search via full text index (with group constraint). * * @api * * @param string $query * @param string $user_groups (optional) comma separated groups * * @return int */ public static function getCountBySearch($query, $user_groups) { if (empty($query)) { return false; } $stmt = DBConnection::getInstance()->prepare("\n SELECT COUNT(*)\n FROM " . self::$TABLE . "\n WHERE\n fti @@ plainto_tsquery(:query)\n AND group_id IN (" . $user_groups . ")\n "); $stmt->assign('query', $query); return $stmt->fetchColumn(); }
public function save() { try { $imageInsert = DBConnection::getInstance()->insert('tbl_home_page_image_slider', array('image_path' => $this->getImagePath(), 'file_name' => $this->getFileName(), 'upload_date' => $this->getUploadDate(), 'modified_by' => $this->getModifiedBy(), 'modification_date' => $this->getModificationDate())); if (!DBConnection::getInstance()->insert('tbl_home_page_image_slider', $imageInsert)) { throw new Exception('There was a problem sending email.'); } } catch (Exception $ex) { error_log($ex->__toString()); } }
public function find($mail = null) { if ($mail) { $field = is_numeric($mail) ? 'mail_id' : 'username'; $data = DBConnection::getInstance()->get('tbl_mail', array($field, '=', $mail)); if ($data->count()) { $this->data = $data->first(); return $this->data; } } return false; }
public function customPrepare($query, $varType, $index) { $conn = DBConnection::getInstance()->getConnection(); $stat = $conn->prepare($query); $stat->bind_param($varType, $index); $stat->execute(); $result = $stat->get_result(); if ($result) { return $result; } else { die($conn->error); } }
public function GetUID() { if ($this->isLoggedIn() == true) { $username = $this->WhoIsLoggedOn(); $sql = "SELECT uid FROM members WHERE mail=?"; $stmt = DBConnection::getInstance()->Prepare($sql); $stmt->bind_param("s", $username); $stmt->execute(); $result = $stmt->get_result(); $object = $result->fetch_object(); return $object->uid; } return null; }
/** * @copydoc PHPUnit_Framework_TestCase::setUp() */ protected function setUp() { // Switch off xdebug screaming (there are // errors in adodb...). PKPTestHelper::xdebugScream(false); // Make sure we have a db connection (some tests // might close it and that affects the next ones). DBConnection::getInstance()->reconnect(); // Backup affected tables. $affectedTables = $this->getAffectedTables(); if (is_array($affectedTables)) { PKPTestHelper::backupTables($affectedTables, $this); } parent::setUp(); }
/** * Set a non-default test configuration * @param $config string the id of the configuration to use * @param $configPath string (optional) where to find the config file, default: 'config' * @param $dbConnect (optional) whether to try to re-connect the data base, default: true */ protected function setTestConfiguration($config, $configPath = 'config', $dbConnect = true) { // Get the configuration file belonging to // this test configuration. $configFile = $this->getConfigFile($config, $configPath); // Avoid unnecessary configuration switches. if (Config::getConfigFileName() != $configFile) { // Switch the configuration file Config::setConfigFileName($configFile); // Re-open the database connection with the // new configuration. if ($dbConnect && class_exists('DBConnection')) { DBConnection::getInstance(new DBConnection()); } } }
public function GetLinks() { $link = new link(); $sql = "\n\t\tSELECT lid, header, www, description, type, date\n\t\tFROM links\n\t\t"; $stmt = DBConnection::getInstance()->Prepare($sql); if ($stmt = DBConnection::getInstance()->Prepare($sql)) { $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_OBJ); } if (is_array($result)) { foreach ($result as $object) { $m_links[] = $link->createLink($object->lid, $object->header, $object->www, $object->description, $object->type, $object->date); } } return $m_links; }
/** * Constructor will normalize the lang and the path as specified as parameters. * The path can be a folder or a file. * * @param $lang '/' netural * @param $path with leading and tailing '/' * @param $name '/' netural */ public function __construct($lang = '', $path = '') { $appConf = AccountManager::getInstance()->appConf; $project = AccountManager::getInstance()->project; // Security $path = str_replace('..', '', $path); $path = str_replace('//', '/', $path); $this->lang = $lang = trim($lang, '/'); $path = trim($path, '.'); $path = trim($path, '/'); // Find if the path is a folder or a file. As it, if the path contains an extension, we assume the path is a file. // Else, it's a folder. $path_parts = pathinfo($path); if (!isset($path_parts['extension'])) { $this->isDir = true; $this->isFile = false; $this->name = ''; $path_parts['dirname'] = isset($path_parts['dirname']) ? $path_parts['dirname'] : ''; $path = $path_parts['dirname'] . '/' . $path_parts['basename']; } else { $this->isDir = false; $this->isFile = true; $this->name = $path_parts['basename']; $path = $path_parts['dirname']; } $path = trim($path, '.'); $path = trim($path, '/'); $path = trim($path, '.'); if (strlen($path) > 0) { $this->path = "/{$path}/"; $this->full_path = $appConf[$project]['vcs.path'] . $lang . '/' . $path . '/' . $this->name; $this->full_new_path = $appConf['GLOBAL_CONFIGURATION']['data.path'] . $appConf[$project]['vcs.module'] . '-new/' . $lang . '/' . $path . '/' . $this->name; $this->full_path_dir = $appConf[$project]['vcs.path'] . $lang . '/' . $path . '/'; $this->full_new_path_dir = $appConf['GLOBAL_CONFIGURATION']['data.path'] . $appConf[$project]['vcs.module'] . '-new/' . $lang . '/' . $path . '/'; // The fallback file : if the file don't exist, we fallback to the EN file witch should always exist $this->full_path_fallback = $appConf[$project]['vcs.path'] . 'en/' . $path . '/' . $this->name; } else { $this->path = '/'; $this->full_path = $appConf[$project]['vcs.path'] . $lang . '/' . $this->name; $this->full_new_path = $appConf['GLOBAL_CONFIGURATION']['data.path'] . $appConf[$project]['vcs.module'] . '-new/' . $lang . '/' . $this->name; $this->full_path_dir = $appConf[$project]['vcs.path'] . $lang . '/'; $this->full_new_path_dir = $appConf['GLOBAL_CONFIGURATION']['data.path'] . $appConf[$project]['vcs.module'] . '-new/' . $lang . '/'; $this->full_path_fallback = $appConf[$project]['vcs.path'] . 'en/' . $this->name; } $this->conn = DBConnection::getInstance(); }
function userExist($user, $password) { $sql = "SELECT Idperfil, Nombrecompleto FROM Usuario WHERE Nombreusuario='" . $user . "' AND Contrasenia=MD5('" . $password . "') AND Activo=1 AND Conectado=0"; $dbh = DBConnection::getInstance(); $statement = $dbh->prepare($sql); $statement->execute(); $result = $statement->fetchAll(); if (count($result) == 0) { return false; } else { $_SESSION['user'] = $user; $_SESSION['password'] = $password; $_SESSION['profile'] = $result[0][0]; $_SESSION['username'] = $result[0][1]; return true; } }
public function insertMessages($datas, $company) { Logger::info('Entering insert messages'); $dbh = DBConnection::getInstance(); Logger::info('Connection object'); try { $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->beginTransaction(); foreach ($datas as $data) { $sql = "INSERT INTO Enviomensaje (Numerotelefono, Mensaje, Fechaenvio, Compania, Usuario) VALUES ('" . '505' . $data->phone . "', '" . $data->message . "', '" . date('c') . "', '" . $company . "', '" . $_SESSION['user'] . "');"; $dbh->exec($sql); } $dbh->commit(); } catch (Exception $e) { $dbh->rollBack(); return false; } return true; }
public static function getAutomaticNumberFromTable($tableName, $pkField) { $result = DBConnection::getInstance()->getAllRecordsFromTable($tableName, $pkField); if (!empty($result)) { $maxId = $result->count(); echo 'max id is: ' . $maxId; return $maxId + 1; } else { return 1; } if ($result) { $row = mysql_fetch_array($result); $nextId = $row[0]; $nextId++; return $nextId; } else { return 0; } }
/** * Perform basic system initialization. * Initializes configuration variables, database connection, and user session. */ function initSystem() { $microTime = Core::microtime(); Registry::set('system.debug.startTime', $microTime); $notes = array(); Registry::set('system.debug.notes', $notes); if (Config::getVar('general', 'installed')) { // Initialize database connection $conn =& DBConnection::getInstance(); if (!$conn->isConnected()) { if (Config::getVar('database', 'debug')) { $dbconn =& $conn->getDBConn(); fatalError('Database connection failed: ' . $dbconn->errorMsg()); } else { fatalError('Database connection failed!'); } } } }
/** * Initialise * */ function __construct() { $am = AccountManager::getInstance(); $appConf = $am->appConf; $project = $am->project; // This entities will not be checked as there are always wrong. We use it into the manual like this : "&url.foo;bar" // Entries should not include the & and ; $this->EntitiesNotChecked = array("url.pecl.package.get", "url.pecl.package"); $this->urlConnectTimeout = 10; $this->userAgent = 'DocWeb Link Crawler (http://doc.php.net)'; $this->pathEntities = $appConf[$project]['entities.url']; $this->forkUrlAllow = function_exists('pcntl_fork') && isset($_ENV['NUMFORKS']); $this->forkNumAllowed = $this->forkUrlAllow ? $_ENV['NUMFORKS'] : 0; $this->supportedSchemes = array('http'); if (extension_loaded('openssl')) { $this->supportedSchemes[] = 'https'; } if (function_exists('ftp_connect')) { $this->supportedSchemes[] = 'ftp'; } $this->conn = DBConnection::getInstance(); }
/** * Create a new database if required. * @return boolean */ function createDatabase() { if (!$this->getParam('createDatabase')) { return true; } // Get database creation sql $dbdict =& NewDataDictionary($this->dbconn); if ($this->getParam('databaseCharset')) { $dbdict->SetCharSet($this->getParam('databaseCharset')); } list($sql) = $dbdict->CreateDatabase($this->getParam('databaseName')); unset($dbdict); if (!$this->executeSQL($sql)) { return false; } // Re-connect to the created database $this->dbconn->disconnect(); $conn = new DBConnection($this->getParam('databaseDriver'), $this->getParam('databaseHost'), $this->getParam('databaseUsername'), $this->getParam('databasePassword'), $this->getParam('databaseName'), true, $this->getParam('connectionCharset') == '' ? false : $this->getParam('connectionCharset')); DBConnection::getInstance($conn); $this->dbconn =& $conn->getDBConn(); if (!$conn->isConnected()) { $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg()); return false; } return true; }
<?php /** * @author: César Bolaños [cbolanos] */ require_once 'class/DBConnection.php'; require_once dirname(__FILE__) . '/util/Logger.php'; $dbh = DBConnection::getInstance(); $sql = "SELECT Compania, Prefijo "; $sql = $sql . "FROM Prefijo "; $sql = $sql . "ORDER BY 1, 2"; $result = $dbh->prepare($sql); $result->execute(); $rows = $result->fetchAll(); $clarocounter = 0; $movistarcounter = 0; $clarodata = array(); $movistardata = array(); for ($i = 0; $i < count($rows); $i++) { $row = $rows[$i]; if ($row[0] == 'claro') { $clarodata[$clarocounter]->value = $row[1]; $clarocounter++; } else { $movistardata[$movistarcounter]->value = $row[1]; $movistarcounter++; } } $response->success = true; $response->claro = $clarodata; $response->movistar = $movistardata;
/** * Execute import of an OCS 1 conference. * If an existing conference path is specified, only content is imported; * otherwise, a new conference is created and all conference settings are also imported. * @param $conferencePath string conference URL path * @param $importPath string local filesystem path to the base OCS 1 directory * @param $options array supported: 'importRegistrations' * @return boolean/int false or conference ID */ function import($conferencePath, $importPath, $options = array()) { @set_time_limit(0); $this->conferencePath = $conferencePath; $this->importPath = $importPath; $this->options = $options; // Force a new database connection $dbconn =& DBConnection::getInstance(); $dbconn->reconnect(true); // Create a connection to the old database if (!@(include $this->importPath . '/include/db.inc.php')) { // Suppress E_NOTICE messages $this->error('Failed to load ' . $this->importPath . '/include/db.php'); return false; } // Assumes no character set (not supported by OCS 1.x) // Forces open a new connection $this->importDBConn = new DBConnection($db_type, $db_host, $db_login, $db_password, $db_name, false, false, true, false, true); $dbconn =& $this->importDBConn->getDBConn(); if (!$this->importDBConn->isConnected()) { $this->error('Database connection error: ' . $dbconn->errorMsg()); return false; } $this->dbtable = $dbtable; $this->importDao = new DAO($dbconn); if (!$this->loadGlobalConfig()) { $this->error('Unsupported or unrecognized OCS version'); return false; } $this->importConference(); $this->importSchedConfs(); $this->importTracks(); $this->importPapers(); $this->importReviewers(); $this->importReviews(); if ($this->hasOption('importRegistrations')) { $this->importRegistrations(); } // Rebuild search index $this->rebuildSearchIndex(); return $this->conferenceId; }
private function __construct() { $this->conn = DBConnection::getInstance(); }
/** * Pre-installation. * @return boolean */ function preInstall() { $this->log('pre-install'); if (!isset($this->dbconn)) { // Connect to the database. $conn =& DBConnection::getInstance(); $this->dbconn =& $conn->getDBConn(); if (!$conn->isConnected()) { $this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg()); return false; } } if (!isset($this->currentVersion)) { // Retrieve the currently installed version $versionDao =& DAORegistry::getDAO('VersionDAO'); $this->currentVersion =& $versionDao->getCurrentVersion(); } if (!isset($this->locale)) { $this->locale = AppLocale::getLocale(); } if (!isset($this->installedLocales)) { $this->installedLocales = array_keys(AppLocale::getAllLocales()); } if (!isset($this->dataXMLParser)) { $this->dataXMLParser = new DBDataXMLParser(); $this->dataXMLParser->setDBConn($this->dbconn); } $result = true; HookRegistry::call('Installer::preInstall', array(&$this, &$result)); return $result; }
/** * Constructor */ function PKPApplication() { // Seed random number generator mt_srand((double) microtime() * 1000000); import('lib.pkp.classes.core.Core'); import('lib.pkp.classes.core.PKPString'); import('lib.pkp.classes.core.Registry'); import('lib.pkp.classes.config.Config'); ini_set('display_errors', Config::getVar('debug', 'display_errors', ini_get('display_errors'))); Registry::set('application', $this); import('lib.pkp.classes.db.DAORegistry'); import('lib.pkp.classes.db.XMLDAO'); import('lib.pkp.classes.cache.CacheManager'); import('classes.security.RoleDAO'); import('lib.pkp.classes.security.Validation'); import('lib.pkp.classes.session.SessionManager'); import('classes.template.TemplateManager'); import('classes.notification.NotificationManager'); import('lib.pkp.classes.statistics.PKPStatisticsHelper'); import('lib.pkp.classes.plugins.PluginRegistry'); import('lib.pkp.classes.plugins.HookRegistry'); import('classes.i18n.AppLocale'); PKPString::init(); $microTime = Core::microtime(); Registry::set('system.debug.startTime', $microTime); $notes = array(); Registry::set('system.debug.notes', $notes); if (Config::getVar('general', 'installed')) { // Initialize database connection $conn = DBConnection::getInstance(); if (!$conn->isConnected()) { if (Config::getVar('database', 'debug')) { $dbconn =& $conn->getDBConn(); fatalError('Database connection failed: ' . $dbconn->errorMsg()); } else { fatalError('Database connection failed!'); } } } }
/** * Return a reference to a single static instance of the database connection. * @return ADONewConnection */ static function &getConn() { $conn = DBConnection::getInstance(); return $conn->getDBConn(); }
public function update($userId, $fields = array()) { if (!DBConnection::getInstance()->update('tbl_user', $userId, $fields)) { throw new Exception('There was a problem updating user profile.'); } }
public function __construct($tblName) { $this->connectionObj = DBConnection::getInstance()->getConnection(); $this->tableName = $tblName; }
function PKPApplication() { // Configure error reporting // FIXME: Error logging needs to be suppressed for strict // and deprecation errors in PHP5 as long as we support PHP 4. // This is primarily for static method warnings and warnings // about use of ... =& new ... Static class members cannot be // declared in PHP4 and ... =& new ... is deprecated since PHP 5. $errorReportingLevel = E_ALL; if (defined('E_STRICT')) { $errorReportingLevel &= ~E_STRICT; } if (defined('E_DEPRECATED')) { $errorReportingLevel &= ~E_DEPRECATED; } @error_reporting($errorReportingLevel); // Instantiate the profiler import('lib.pkp.classes.core.PKPProfiler'); $pkpProfiler = new PKPProfiler(); // Begin debug logging Console::logMemory('', 'PKPApplication::construct'); Console::logSpeed('PKPApplication::construct'); // Seed random number generator mt_srand((double) microtime() * 1000000); import('lib.pkp.classes.core.Core'); import('lib.pkp.classes.core.String'); import('lib.pkp.classes.core.Registry'); import('lib.pkp.classes.config.Config'); if (Config::getVar('debug', 'display_errors')) { // Try to switch off normal error display when error display // is being managed by OJS. @ini_set('display_errors', false); } if (Config::getVar('debug', 'deprecation_warnings')) { // Switch deprecation warnings back on. This can only be done // after declaring the Config class as we need access to the // configuration and we cannot declare the Config class before // we've switched of deprecation warnings as its declaration // causes warnings itself. // FIXME: When we drop PHP4 support and can declare static methods // as such then we can also include E_STRICT/E_DEPRECATED here as // nearly all strict/deprecated warnings concern PHP4 support. @error_reporting($errorReportingLevel); } Registry::set('application', $this); import('lib.pkp.classes.db.DAORegistry'); import('lib.pkp.classes.db.XMLDAO'); import('lib.pkp.classes.cache.CacheManager'); import('classes.security.Validation'); import('lib.pkp.classes.session.SessionManager'); import('classes.template.TemplateManager'); import('lib.pkp.classes.plugins.PluginRegistry'); import('lib.pkp.classes.plugins.HookRegistry'); import('classes.i18n.AppLocale'); String::init(); set_error_handler(array($this, 'errorHandler')); $microTime = Core::microtime(); Registry::set('system.debug.startTime', $microTime); $notes = array(); Registry::set('system.debug.notes', $notes); Registry::set('system.debug.profiler', $pkpProfiler); if (Config::getVar('general', 'installed')) { // Initialize database connection $conn =& DBConnection::getInstance(); if (!$conn->isConnected()) { if (Config::getVar('database', 'debug')) { $dbconn =& $conn->getDBConn(); fatalError('Database connection failed: ' . $dbconn->errorMsg()); } else { fatalError('Database connection failed!'); } } } }
/** * Get the driver for this connection. * @return string */ function getDriver() { $conn =& DBConnection::getInstance(); return $conn->getDriver(); }
/** * Execute import of an OJS 1 journal. * If an existing journal path is specified, only content is imported; * otherwise, a new journal is created and all journal settings are also imported. * @param $journalPath string journal URL path * @param $importPath string local filesystem path to the base OJS 1 directory * @param $options array supported: 'importSubscriptions' * @return boolean/int false or journal ID */ function import($journalPath, $importPath, $options = array()) { @set_time_limit(0); $this->journalPath = $journalPath; $this->importPath = $importPath; $this->options = $options; // Force a new database connection $dbconn =& DBConnection::getInstance(); $dbconn->reconnect(true); // Create a connection to the old database if (!@(include $this->importPath . '/include/db.php')) { // Suppress E_NOTICE messages $this->error('Failed to load ' . $this->importPath . '/include/db.php'); return false; } // Assumes no character set (not supported by OJS 1.x) // Forces open a new connection $this->importDBConn =& new DBConnection($db_config['type'], $db_config['host'], $db_config['uname'], $db_config['password'], $db_config['name'], false, false, true, false, true); $dbconn =& $this->importDBConn->getDBConn(); if (!$this->importDBConn->isConnected()) { $this->error('Database connection error: ' . $dbconn->errorMsg()); return false; } $this->importDao =& new DAO($dbconn); if (!$this->loadJournalConfig()) { $this->error('Unsupported or unrecognized OJS version'); return false; } // Determine if journal already exists $journalDao =& DAORegistry::getDAO('JournalDAO'); $journal =& $journalDao->getJournalByPath($this->journalPath); $this->importJournal = $journal == null; // Import data if ($this->importJournal) { $this->importJournal(); $this->importReadingTools(); } else { $this->journalId = $journal->getJournalId(); } $this->importUsers(); if ($this->hasOption('importSubscriptions') && version_compare($this->importVersion, OJS1_MIN_VERSION_SUBSCRIPTIONS) >= 0) { // Subscriptions requires OJS >= 1.1.8 $this->importSubscriptions(); } $this->importSections(); $this->importIssues(); $this->importArticles(); // Rebuild search index $this->rebuildSearchIndex(); if ($this->hasOption('redirect')) { $this->generateRedirects(); } return $this->journalId; }
* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * PHP Template. * Author: Sheetal Patil. Sun Microsystems, Inc. * * login.php processes the login request and forwards to the home page. * */ session_start(); require_once "../etc/config.php"; $connection = DBConnection::getInstance(); $register = Users_Controller::getInstance(); if ($_POST['submit'] == "Login") { $un = $_POST['user_name']; $pwd = $_POST['password']; $result = $register->authenticate($un, $pwd, $connection); if ($result->next()) { session_register("uname"); $uname = $un; $sid = session_id(); $_SESSION["uname"] = $uname; $_SESSION["sid"] = $sid; $success = "authenticated"; } unset($result); $numFriendshipReq = $register->numFriendshipRequests($un, $connection);
/** * Constructor */ function PKPApplication() { // Seed random number generator mt_srand((double) microtime() * 1000000); import('lib.pkp.classes.core.Core'); import('lib.pkp.classes.core.String'); import('lib.pkp.classes.core.Registry'); import('lib.pkp.classes.config.Config'); ini_set('display_errors', Config::getVar('debug', 'display_errors', ini_get('display_errors'))); Registry::set('application', $this); import('lib.pkp.classes.db.DAORegistry'); import('lib.pkp.classes.db.XMLDAO'); import('lib.pkp.classes.cache.CacheManager'); import('classes.security.RoleDAO'); import('lib.pkp.classes.security.Validation'); import('lib.pkp.classes.session.SessionManager'); import('classes.template.TemplateManager'); import('classes.notification.NotificationManager'); import('lib.pkp.classes.statistics.PKPStatisticsHelper'); import('lib.pkp.classes.plugins.PluginRegistry'); import('lib.pkp.classes.plugins.HookRegistry'); import('classes.i18n.AppLocale'); // Set site time zone // Starting from PHP 5.3.0 PHP will throw an E_WARNING if the default // time zone is not set and date/time functions are used // http://pl.php.net/manual/en/function.date-default-timezone-set.php $timeZone = AppLocale::getTimeZone(); date_default_timezone_set($timeZone); String::init(); $microTime = Core::microtime(); Registry::set('system.debug.startTime', $microTime); $notes = array(); Registry::set('system.debug.notes', $notes); if (Config::getVar('general', 'installed')) { // Initialize database connection $conn = DBConnection::getInstance(); if (!$conn->isConnected()) { if (Config::getVar('database', 'debug')) { $dbconn =& $conn->getDBConn(); fatalError('Database connection failed: ' . $dbconn->errorMsg()); } else { fatalError('Database connection failed!'); } } } }