/** * Opens an SQLite database. * * @param type $filename Path to the SQLite database, or :memory: to use * in-memory database. * * @throws SQLiteException on failure. */ private function open($filename) { try { $this->link = new PDO('sqlite:' . $filename); } catch (PDOException $e) { throw new SQLiteException($e->getMessage()); } $this->link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
/** * Creates a connection to the database. */ protected function _connect() { if ($this->connection) { return; } $this->connection = new PDO($this->_dsn(), $this->cfg->user, $this->cfg->pass, $this->cfg->driverOptions); foreach ($this->cfg->conQuery as $q) { $this->connection->query($q); } $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
function __construct() { /*//Conectando ao banco de dados $this->o_db = new PDO("sqlite:./databases/db.sq3");*/ //Mudando para MySQL $st_host = 'localhost'; $st_banco = 'ufpa_pdti'; $st_usuario = 'root'; $st_senha = ''; $st_dsn = "mysql:host={$st_host};dbname={$st_banco}"; $this->o_db = new PDO($st_dsn, $st_usuario, $st_senha); $this->o_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
/** * Query the database * * @param string $queryStr SQL query string * @return resource MySQL result set */ public function query($queryStr, $unbuffered = false) { // set the result to false $result = false; try { // set buffer attribute $this->connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, !$unbuffered); $result = $this->connection->query($queryStr); $this->_result = $result; } catch (PDOException $e) { $this->_handleError($e, true, "Query String: " . $queryStr); } return $result; }
public function getConnection() { try { if ($this->dbh == null) { $this->dbh = new PDO($this->connectionString, $this->username, $this->password); $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbh->query("SET NAMES 'utf8'"); } return $this->dbh; } catch (Exception $e) { Logger::getLogger('system.services.Storage.GenericDAO')->error('Cannot connect to the database: ' . $e->getMessage()); throw $e; } }
function __construct($db = null) { if (class_exists('jqGridDB') && $db) { $interface = jqGridDB::getInterface(); } else { $interface = 'chartarray'; } $this->conn = $db; if ($interface == 'pdo') { try { $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->dbtype = $this->conn->getAttribute(PDO::ATTR_DRIVER_NAME); } catch (Exception $e) { } } else { $this->dbtype = $interface; } # Set Default Values $this->coptions['credits']['enabled'] = false; $this->coptions['chart']['renderTo'] = ''; $this->coptions['series'] = array(); $this->i_serie_index = 0; $this->jscode = false; }
/** * 执行查询语句 * * @access public * @param $sql * @return array|boolean */ public function query($sql) { $this->connect(); if (!$this->_linkId) { return false; } try { $this->_linkId->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL); $this->_queryId = $this->_linkId->query($sql); } catch (PDOException $e) { trigger_error('MySQL PDO query error: ' . $e->getMessage() . ' [' . $sql . ']'); } $result = array(); if ($this->_queryId) { $this->_queryId->setFetchMode(PDO::FETCH_ASSOC); $result = $this->_queryId->fetchAll(); $this->_numRows = count($result); } return $result; }
/** * Fügt eine Beschreibung der Suchfunktionalität ein * @param string Name der Suchseite, z. B. "Search" * @param string Beschreibung der Suchseite, z. B. * "Search SitePoint..." * @param string URL der Suchseite * @param string GET-Variable für die Suche, z. B. * "q" für "?q=" * @return void * @access public */ public function addSearch($title, $desc, $url, $var) { $this->addChannelTextInput($url); $this->textinput = $this->dom->createElement('textinput'); $this->textinput->setAttribute('rdf:about', $url); $titleNode = $this->dom->createElement('title'); $titleNodeText = $this->dom->createTextNode($title); $titleNode->appendChild($titleNodeText); $this->textinput->appendChild($titleNode); $descNode = $this->dom->createElement('description'); $descNodeText = $this->dom->createTextNode($desc); $descNode->appendChild($descNodeText); $this->textinput->appendChild($descNode); $nameNode = $this->dom->createElement('name'); $nameNodeText = $this->dom->createTextNode($var); $nameNode->appendChild($nameNodeText); $this->textinput->appendChild($nameNode); $linkNode = $this->dom->createElement('link'); $linkNodeText = $this->dom->createTextNode($url); $linkNode->appendChild($linkNodeText); $this->textinput->appendChild($linkNode); }
function __construct() { $this->o_db = new PDO('mysql:host=localhost;dbname=teste', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $this->o_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->o_db->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING); }