public function restoreUserFromUsername( DatabaseConnection $connection ) { if(!isset($connection) || !isset($this->username)) { $this->isAuthenticated = false; return$this->isAuthenticated; } if( !$connection->isConnected ) { if( !$connection->Connect() ){ return $this->isAuthenticated; } } $query = "select userId, username, userLevel, ipaddress, isLoggedIn, lastLogin from users where username='******';"; if( !$connection->query( $query ) ) { return $this->isAuthenticated; } if( 1 > $connection->getNumRows() ) { //echo "user {$query}"; //print_r($connection->getObject()); return $this->isAuthenticated; } $user = $connection->getObject(); $this->userLevel = $user->userLevel; $this->lastLogin = $user->lastLogin; $this->ipaddress = $user->ipaddress; $this->isAuthenticated = $user->isLoggedIn; }
/** * @param string $userUid * * @return int Number of destroyed sessions. */ public function destroySessions($userUid) { // Run two separate queries so we know exactly how many sessions are deleted. $destroyed = $this->connection->query('DELETE s FROM {sessions} s INNER JOIN {oxygen_session} os ON os.sid = s.sid WHERE os.uid = :uid', array('uid' => $userUid), array('return' => Database::RETURN_AFFECTED)); $this->connection->query('DELETE FROM {oxygen_session} WHERE uid = :uid', array('uid' => $userUid)); return $destroyed; }
/** * @brief Loads a wiki page * * Will attempt to load a wiki page from the database. If revision is not * specified, the latest revision will be loaded. * * @param String $page * @param Int $revision * @return Boolean True on success, false otherwise */ function loadWikiPage($page, $revision = null) { $db = new DatabaseConnection(); list($ns, $name) = $this->splitUri($page, 'wiki'); if (!$revision) { $pd = $db->getSingleRow("SELECT * FROM wikipages WHERE pagens=%s AND pagename=%s " . "ORDER BY revision DESC LIMIT 1;", $ns, $name); } else { $pd = $db->getSingleRow("SELECT * FROM wikipages WHERE pagens=%s AND pagename=%s AND " . "revision<%d ORDER BY revision DESC LIMIT 1;", $ns, $name, $revision); } if ($pd) { $revs = $db->getSingleRow("SELECT revision FROM wikipages WHERE pagens=%s AND pagename=%s", $ns, $name); foreach ($revs as $rev) { $this->revisions[] = $rev['revision']; } if ($pd['format'] != NULL) { $this->markup = $pd['markuptype']; $this->parser = markup::factory($this->markup); } $this->content = $pd['content']; $this->pagerevision = $pd['revision']; $this->modified = false; $this->pagens = $pd['pagens']; $this->pagename = $pd['pagename']; $this->pagetitle = $pd['pagetitle']; return true; } else { return false; } }
public function getUserList() { $dbconn = new DatabaseConnection('localhost', 'user', 'password'); $results = $dbconn->query('select name from user'); sort($results); return $results; }
public function refreshUserList() { //assim evitamos a necessidade de consultar o banco a cada requisição de lista $dbconn = new DatabaseConnection('localhost', 'user', 'password'); $results = $dbconn->query('select name from user'); $this->setUserList(sort($results)); }
function addSubjects($name) { $sql = "INSERT INTO subjects VALUES ('', ?)"; $string = array($name); $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $db->queryWithoutResult($sql, $string, true, "s"); }
public static function insert($table, $fields, $values, $nestedRows = false, $rowsPerInsert = 100, $returnQueries = false) { if (!self::$default && self::$connectHandler) { self::$connectHandler[0]->{self::$connectHandler[1]}(); } return self::$default->insert($table, $fields, $values, $nestedRows, $rowsPerInsert, $returnQueries); }
/** * Get constraint type handler for driver * * @param \DatabaseConnection $connection * @param string $type * * @return ConstraintInterface */ public function get(\DatabaseConnection $connection, $type) { $driver = $connection->driver(); if (isset($this->instances[$driver][$type])) { return $this->instances[$driver][$type]; } return $this->instances[$driver][$type] = $this->createInstance($connection, $type); }
function staticText($slug) { $db = new DatabaseConnection(); $text = $db->getSingleRow("SELECT * FROM statictext WHERE slug=%s", $slug); if ($text) { return $text['content']; } }
function showStart() { $this->loadTemplate(); $controller = new DatabaseConnection(); $controller->raw('CALL registraVisita()'); $controller = null; include 'view/welcome.php'; }
function getStudentIds() { $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $sql = "SELECT id FROM students"; $string = array(); $res = $db->select($sql, $string, false, ''); return $res; }
public function getListaUsuario($dbconn = null) { if (!isset($dbconn) || !$dbconn instanceof DatabaseConnection) { $dbconn = new DatabaseConnection('localhost', 'root', ''); } $results = $dbconn->query('SELECT name FROM users'); sort($results); return $results; }
public function deleteLocation($id) { $db = new DatabaseConnection(); $conn = $db->connectToDB(); $result = $db->updateDatabase("DELETE FROM location where id = {$id}"); $db->closeDBConnection($conn); header("Content-Type: application/json"); echo json_encode($result); }
protected function cleanup() { // Test could have been skipped if (null !== $this->dbConnection) { foreach (array('apb_queue', 'apb_msg', 'apb_msg_chan', 'apb_sub', 'apb_chan') as $table) { $this->dbConnection->query("DELETE FROM {" . $table . "}"); } } }
public function submitComment() { $conn = new DatabaseConnection(); if (!isset($_GET['replyid'])) { $sentence = 'CALL addComment(' . $_SESSION['bookid'] . ',' . $_SESSION['id'] . ",'" . $_POST['comment'] . "')"; } else { $sentence = 'CALL addReply(' . $_SESSION['bookid'] . ',' . $_SESSION['id'] . ',' . $conn->quote($_POST['reply']) . ',' . $_GET['replyid'] . ')'; } $conn->query($sentence); }
public function __construct() { $this->dbTable = 'product'; $connection = new DatabaseConnection(); try { $this->database = $connection->SetupDatabase(); } catch (\Exception $e) { throw $e; } }
public function addEvent(AuditEvent $event) { $event->setComponent($this->_component); $cn = get_class($event); $sev = serialize($event); // Shove into DB -- echo $sev; echo $cn . "\n\n" . $sev . "\n"; $db = new DatabaseConnection(); $db->insertRow("INSERT INTO auditlog " . "eventclass,component,severity,eventdate,data) " . "VALUES (%s,%s,%d,%d,NOW(),%s)", $cn, $event->getComponent(), $event->getSeverity(), $event->getAssociatedUserId(), $sev); }
function savepost() { $post = new WebForm($this->gbform); if (!$post->isValid()) { // Form is invalid, post it back to the user to allow correction } else { $db = new DatabaseConnection(); $db->insertRow("INSERT INTO guestbook (name,email,website,message) VALUES (%s,%s,%s,%s)", $post->name, $post->email, $post->website, $post->message); } }
/** * Testcase Constructor. * * @return void */ public function setUpPool() { $this->pool = $this->getMockBuilder('Lunr\\Gravity\\Database\\DatabaseConnectionPool')->disableOriginalConstructor()->getMock(); $this->logger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->db = $this->getMockBuilder('Lunr\\Gravity\\Database\\MySQL\\MySQLConnection')->disableOriginalConstructor()->getMock(); $escaper = $this->getMockBuilder('Lunr\\Gravity\\Database\\MySQL\\MySQLQueryEscaper')->disableOriginalConstructor()->getMock(); $this->db->expects($this->once())->method('get_query_escaper_object')->will($this->returnValue($escaper)); $this->dao = $this->getMockBuilder('Lunr\\Gravity\\Database\\DatabaseAccessObject')->setConstructorArgs(array($this->db, $this->logger, $this->pool))->getMockForAbstractClass(); $this->reflection_dao = new ReflectionClass('Lunr\\Gravity\\Database\\DatabaseAccessObject'); }
protected static final function openConnection($driver) { $adapter = 'Adapter' . $driver; include_once dirname(__FILE__) . '/adapter/' . $adapter . '.php'; $connection = new DatabaseConnection(new $adapter()); $cfg = self::getConnectionConf(); $connection->connect($cfg['engine'], $cfg['hostname'], $cfg['database'], $cfg['username'], $cfg['password']); return $connection; // end function }
public function testLastID() { require __DIR__ . '/config/database_test.php'; $db = new DatabaseConnection($host, $database, $user, $password); $insert_result = $db->query("INSERT INTO characters (id, name, description, type, dead, stage, hp) \r\n\t\t\tVALUES ('9999', 'Carla', 'The swordmaster of Melee Island', 'pirate', 'false', '4', '87');"); $actual = $db->lastID(); $expected = '9999'; $delete_result = $db->query("DELETE FROM characters WHERE id = '9999'"); $this->assertNotEmpty($actual, 'Function LastID returning empty value. Check TestDatabaseConnection::lastID()'); $this->assertEquals($expected, $actual, 'Function LastID not returning expected value. Check TestDatabaseConnection::lastID()'); }
/** * {@inheritdoc} */ public function useNonce($nonce, $expiresAt) { if ($expiresAt < time()) { throw new Oxygen_Exception(Oxygen_Exception::NONCE_EXPIRED); } $cleanNonce = strtr($nonce, ['-' => '']); $nonceUsed = (bool) $this->connection->query('SELECT 1 FROM {oxygen_nonce} WHERE nonce = :nonce', [':nonce' => $cleanNonce])->fetchField(); if ($nonceUsed) { throw new Oxygen_Exception(Oxygen_Exception::NONCE_ALREADY_USED); } $this->connection->query('INSERT INTO {oxygen_nonce} (nonce, expires) VALUES (:nonce, :expires)', [':nonce' => $cleanNonce, ':expires' => $expiresAt]); }
function getAllPosts() { // Acquire a handle to the database. $db = new DatabaseConnection(); // Query the posts and assign the result to a postcollection. $rs = $db->getRows("SELECT * FROM blogposts ORDER BY pubdate DESC"); $coll = array(); foreach ($rs as $post) { $coll[] = new BlogPost($post); } // Finally return it return $coll; }
function __construct(DatabaseConnection $parent) { //echo "Opening Connection\n"; if ($parent->is_transaction()) { $this->using_savepoints = true; $this->savepoint_name = 'transaction_' . uniqid(); $parent->query('SAVEPOINT ' . pg_escape_identifier($this->savepoint_name)); } else { $this->using_savepoints = false; $parent->query("START TRANSACTION"); } $this->parent_connection = $parent; }
function addNewStudent($login_code, $name, $birth, $pass, $email, $pn, $city, $subj) { $sql = "INSERT INTO teachers VALUES ('', ?, ?, ?, ?, ?, ?, ?)"; $string = array($login_code, $name, $birth, $pass, $email, $pn, $city); $db = new DatabaseConnection("localhost", "adminuser", "asd12345", "school"); $db->queryWithoutResult($sql, $string, true, "sssssss"); $sql = 'SELECT id FROM teachers WHERE code = ?'; $string = array($login_code); $res = $db->select($sql, $string, true, 's'); $sql = "INSERT INTO teacher_subj VALUES (?,?)"; $string = array($res[0]['id'], $subj); $db->queryWithoutResult($sql, $string, true, "is"); return true; }
/** * Create a new collection using an uri or a pattern * * f.ex. tag:foo, category:bar, title:*, *, user:bob * */ public function __construct($selection, Paginator $paginator = null) { // Create a collection from a tag, category, title, user etc. $db = new DatabaseConnection(); $sql = $db->quote('SELECT * FROM galleryitems'); $count = $db->quote('SELECT COUNT(*) AS numitems FROM galleryitems'); // If we have a paginator, make use of it if ($paginator) { $sql .= ' ' . $paginator->getSqlLimit(); } // Then select the rows and the total count $rs = $db->getRows($sql); $rsc = $db->getSingleRow($count); }
/** * {@inheritdoc} */ public function find($string, $prefix = true, $limit = 20) { if ($prefix) { $escaped = db_like($string) . '%'; } else { $escaped = '%' . db_like($string) . '%'; } $map = $this->db->select('node', 'n')->fields('n', ['nid', 'title'])->condition('n.type', $this->bundle)->condition('n.title', $escaped, 'LIKE')->orderBy('n.title')->range(0, $limit)->execute()->fetchAllKeyed(); $ret = []; foreach ($map as $id => $title) { $ret[] = new EntityFinderResult('node', $id, $title, $this->getLabel()); } return $ret; }
public function getUserList() { $server = "localhost"; $user = "******"; $password = "******"; $dbconn = new DatabaseConnection($server, $user, $password); if ($dbconn->connect_error) { die("Conexão falhou: " . $dbconn->connection_error); } else { $results = $dbconn->query('select name from user'); sort($results); return $results; } }
/** * ItemProcFunc for CType items * * @param array $params : The array of parameters that is used to render the item list * * @return void */ public function itemsProcFunc(&$params) { if ((int) $params['row']['pid'] > 0) { $this->checkForAllowedCTypes($params['items'], $params['row']['pid'], $params['row']['colPos'], $params['row']['tx_gridelements_container'], $params['row']['tx_gridelements_columns']); } else { $this->init((int) $params['row']['pid']); // negative uid_pid values indicate that the element has been inserted after an existing element // so there is no pid to get the backendLayout for and we have to get that first $existingElement = $this->databaseConnection->exec_SELECTgetSingleRow('pid, CType, colPos, tx_gridelements_container, tx_gridelements_columns', 'tt_content', 'uid=' . -(int) $params['row']['pid']); if ((int) $existingElement['pid'] > 0) { $this->checkForAllowedCTypes($params['items'], $existingElement['pid'], $existingElement['colPos'], $existingElement['tx_gridelements_container'], $existingElement['tx_gridelements_columns']); } } }
/** * Alter the results from the getFieldTypeMap() methods in the schema class. * * @param array $map * The array mapping of Drupal schema field names to DB-native field types. * @param DatabaseSchema $schema * The database schema class. * @param DatabaseConnection $connection * The database connection class since the $schema object doesn't offer * $schema->connection as a public property. */ function hook_schema_field_type_map_alter(array &$map, DatabaseSchema $schema, DatabaseConnection $connection) { switch ($connection->getType()) { case 'mysql': $map['datetime:normal'] = 'DATETIME'; break; case 'pgsql': $map['datetime:normal'] = 'timestamp without time zone'; break; case 'sqlite': $map['datetime:normal'] = 'VARCHAR'; break; } }