本文整理汇总了PHP中Creole类的典型用法代码示例。如果您正苦于以下问题:PHP Creole类的具体用法?PHP Creole怎么用?PHP Creole使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Creole类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPeer
/**
* @return mixed
*/
protected function getPeer()
{
if (!$this->peer) {
require_once 'creole/Creole.php';
\Creole::registerDriver('*', 'creole.contrib.DebugConnection');
$this->peer = $this->createPeer();
}
return $this->peer;
}
示例2: connect
/**
* connect()
*/
public function connect($dsninfo, $flags = 0)
{
if (!($driver = Creole::getDriver($dsninfo['phptype']))) {
throw new SQLException("No driver has been registered to handle connection type: {$type}");
}
$connectionClass = Creole::import($driver);
$this->childConnection = new $connectionClass();
$this->log("connect(): DSN: " . var_export($dsninfo, true) . ", FLAGS: " . var_export($flags, true));
return $this->childConnection->connect($dsninfo, $flags);
}
示例3: testFetchmodeAssocNoChange
/**
* Test an ASSOC fetch with a connection that has the Creole::NO_ASSOC_LOWER flag set.
*/
public function testFetchmodeAssocNoChange()
{
$exch = DriverTestManager::getExchange('ResultSetTest.ALL_RECORDS');
$conn2 = Creole::getConnection(DriverTestManager::getDSN(), Creole::NO_ASSOC_LOWER);
DriverTestManager::initDb($conn2);
$rs = $conn2->executeQuery($exch->getSql(), ResultSet::FETCHMODE_ASSOC);
$rs->next();
$keys = array_keys($rs->getRow());
$this->assertEquals("PRODUCTID", $keys[0], 0, "Expected to find uppercase column name for Oracle.");
$rs->close();
}
示例4: getConnection
public static function getConnection()
{
if (!extension_loaded(__DBTYPE__)) {
throw new Exception("php does not have database exstention for : " . __DBTYPE__);
}
if (!class_exists('Creole')) {
throw new Exception("Could not find Creole Database Abstraction Layer in php_includes");
}
$dsn = array('phptype' => __DBTYPE__, 'hostspec' => __DBHOST__, 'username' => __DBUSR__, 'password' => __DBUSERPW__, 'database' => __DBNAME__);
return Creole::getConnection($dsn);
}
示例5: addConfig
public function addConfig()
{
if ($this->hasParameter('host')) {
$this->setParameter('hostspec', $this->getParameter('host'));
}
if ($dsn = $this->getParameter('dsn')) {
require_once 'creole/Creole.php';
$params = Creole::parseDSN($dsn);
$options = array('phptype', 'hostspec', 'database', 'username', 'password', 'port', 'protocol', 'encoding', 'persistent', 'socket', 'compat_assoc_lower', 'compat_rtrim_string');
foreach ($options as $option) {
if (!$this->getParameter($option) && isset($params[$option])) {
$this->setParameter($option, $params[$option]);
}
}
}
self::$config['propel']['datasources'][$this->getParameter('datasource')] = array('adapter' => $this->getParameter('phptype'), 'connection' => array('phptype' => $this->getParameter('phptype'), 'hostspec' => $this->getParameter('hostspec'), 'database' => $this->getParameter('database'), 'username' => $this->getParameter('username'), 'password' => $this->getParameter('password'), 'port' => $this->getParameter('port'), 'encoding' => $this->getParameter('encoding'), 'persistent' => $this->getParameter('persistent'), 'protocol' => $this->getParameter('protocol'), 'socket' => $this->getParameter('socket'), 'compat_assoc_lower' => $this->getParameter('compat_assoc_lower'), 'compat_rtrim_string' => $this->getParameter('compat_rtrim_string')));
}
示例6: connect
/**
* @see Connection::connect()
*/
public function connect($dsninfo, $flags = 0)
{
if (!function_exists('odbc_connect')) {
throw new SQLException('odbc extension not loaded');
}
$adapterclass = isset($dsninfo['adapter']) ? $dsninfo['adapter'] : null;
if (!$adapterclass) {
$adapterclass = 'ODBCAdapter';
} else {
$adapterclass .= 'Adapter';
}
Creole::import('creole.drivers.odbc.adapters.' . $adapterclass);
$this->adapter = new $adapterclass();
$this->dsn = $dsninfo;
$this->flags = $flags;
if (!($this->flags & Creole::COMPAT_ASSOC_LOWER) && !$this->adapter->preservesColumnCase()) {
trigger_error('Connection created without Creole::COMPAT_ASSOC_LOWER, ' . 'but driver does not support case preservation.', E_USER_WARNING);
$this->flags != Creole::COMPAT_ASSOC_LOWER;
}
$persistent = ($flags & Creole::PERSISTENT) === Creole::PERSISTENT;
if ($dsninfo['database']) {
$odbcdsn = $dsninfo['database'];
} elseif ($dsninfo['hostspec']) {
$odbcdsn = $dsninfo['hostspec'];
} else {
$odbcdsn = 'localhost';
}
$user = @$dsninfo['username'];
$pw = @$dsninfo['password'];
$connect_function = $persistent ? 'odbc_pconnect' : 'odbc_connect';
$conn = @$connect_function($odbcdsn, $user, $pw, SQL_CUR_USE_IF_NEEDED);
if (!is_resource($conn)) {
throw new SQLException('connect failed', $this->nativeError(), $odbcdsn);
}
$this->dblink = $conn;
/**
* This prevents blob fields from being fetched when a row is loaded
* from a recordset. Clob fields however are loaded with up to
* 'odbc.defaultlrl' data. This should be the default anyway, but we'll
* set it here just to keep things consistent.
*/
@odbc_binmode(0, ODBC_BINMODE_PASSTHRU);
@odbc_longreadlen(0, ini_get('odbc.defaultlrl'));
}
示例7: Mail_Queue_Container_creole
/**
* Constructor
*
* Mail_Queue_Container_creole()
*
* @param mixed $options An associative array of connection option.
*
* @access public
*/
function Mail_Queue_Container_creole($options)
{
if (!is_array($options) || !isset($options['dsn']) && !isset($options['connection'])) {
$this->constructor_error = new Mail_Queue_Error(MAILQUEUE_ERROR_NO_OPTIONS, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, 'No dns specified!');
return;
}
if (isset($options['mail_table'])) {
$this->mail_table = $options['mail_table'];
}
if (!empty($options['pearErrorMode'])) {
$this->pearErrorMode = $options['pearErrorMode'];
}
try {
$this->db = isset($options['connection']) ? $options['connection'] : Creole::getConnection($options['dsn']);
} catch (SQLException $e) {
$this->constructor_error = new Mail_Queue_Error(MAILQUEUE_ERROR_CANNOT_CONNECT, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, 'CREOLE::connect failed: ' . $e->getMessage());
return;
}
$this->setOption();
}
示例8: getConnection
/**
* Establishes a Creole database connection
*
* @return object The connection
*/
protected function getConnection()
{
// Attemtp to connect to a database.
$this->dsn = Creole::parseDSN($this->dbUrl);
if ($this->dbUser) {
$this->dsn["username"] = $this->dbUser;
}
if ($this->dbPassword) {
$this->dsn["password"] = $this->dbPassword;
}
if ($this->dbDriver) {
Creole::registerDriver($this->dsn['phptype'], $this->dbDriver);
}
$con = Creole::getConnection($this->dsn);
$this->log("DB connection established");
return $con;
}
示例9: __construct
function __construct()
{
\Creole::registerDriver('dbarray', 'creole.contrib.DBArrayConnection');
}
示例10: connect
/**
* Connect to the database.
*
* @throws <b>AgaviDatabaseException</b> If a connection could not be
* created.
*
* @author Sean Kerr <skerr@mojavi.org>
* @author David Zülke <dz@bitxtender.com>
* @since 0.9.0
*/
protected function connect()
{
try {
// determine how to get our settings
$method = $this->getParameter('method', 'normal');
switch ($method) {
case 'normal':
// get parameters normally
// all params, because we can't know all names!
$dsn = $this->getParameters();
// remove our own
unset($dsn['method']);
unset($dsn['classpath']);
unset($dsn['compat_assoc_lower']);
unset($dsn['compat_rtrim_string']);
unset($dsn['persistent']);
break;
case 'dsn':
$dsn = $this->getParameter('dsn');
if ($dsn == null) {
// missing required dsn parameter
$error = 'Database configuration specifies method "dsn", but is missing dsn parameter';
throw new AgaviDatabaseException($error);
}
break;
case 'server':
// construct a DSN connection string from existing $_SERVER
// values
$dsn = $this->loadDSN($_SERVER);
break;
case 'env':
// construct a DSN connection string from existing $_ENV
// values
$dsn = $this->loadDSN($_ENV);
break;
default:
// who knows what the user wants...
$error = 'Invalid CreoleDatabase parameter retrieval method "%s"';
$error = sprintf($error, $method);
throw new AgaviDatabaseException($error);
}
// get creole class path
$classPath = $this->getParameter('classpath');
// include the creole file
if ($classPath == null) {
require_once 'creole/Creole.php';
} else {
require_once $classPath;
}
// set our flags
$compatAssocLower = $this->getParameter('compat_assoc_lower', false);
$compatRtrimString = $this->getParameter('compat_rtrim_string', false);
$persistent = $this->getParameter('persistent', false);
$flags = 0;
$flags |= $compatAssocLower ? Creole::COMPAT_ASSOC_LOWER : 0;
$flags |= $compatRtrimString ? Creole::COMPAT_RTRIM_STRING : 0;
$flags |= $persistent ? Creole::PERSISTENT : 0;
// do the duuuurtay work, right thurr
if ($flags > 0) {
$this->connection = Creole::getConnection($dsn, $flags);
} else {
$this->connection = Creole::getConnection($dsn);
}
// get our resource
$this->resource = $this->connection->getResource();
foreach ((array) $this->getParameter('init_queries') as $query) {
$this->connection->executeUpdate($query);
}
} catch (SQLException $e) {
// the connection's foobar'd
throw new AgaviDatabaseException($e->toString());
}
}
示例11: connect
/**
* Connect to the database.
*
* @throws <b>sfDatabaseException</b> If a connection could not be created.
*/
public function connect()
{
try {
// determine how to get our settings
$method = $this->getParameter('method', 'normal');
switch ($method) {
case 'normal':
// get parameters normally, and all are required
$database = $this->getParameter('database', null);
$hostspec = $this->getParameter('hostspec') ? $this->getParameter('hostspec') : ($this->getParameter('host') ? $this->getParameter('hostspec') : null);
$password = $this->getParameter('password', null);
$phptype = $this->getParameter('phptype', null);
$username = $this->getParameter('username', null);
$port = $this->getParameter('port', null);
$encoding = $this->getParameter('encoding', null);
$dsn = array('database' => $database, 'hostspec' => $hostspec, 'password' => $password, 'phptype' => $phptype, 'username' => $username, 'port' => $port, 'encoding' => $encoding);
break;
case 'dsn':
$dsn = $this->getParameter('dsn');
if ($dsn == null) {
// missing required dsn parameter
$error = 'Database configuration specifies method "dsn", but is missing dsn parameter';
throw new sfDatabaseException($error);
}
break;
case 'server':
// construct a DSN connection string from existing $_SERVER values
$dsn =& $this->loadDSN($_SERVER);
break;
case 'env':
// construct a DSN connection string from existing $_ENV values
$dsn =& $this->loadDSN($_ENV);
break;
default:
// who knows what the user wants...
$error = 'Invalid CreoleDatabase parameter retrieval method "%s"';
$error = sprintf($error, $method);
throw new sfDatabaseException($error);
}
// get creole class path
$classPath = $this->getParameter('classpath');
// include the creole file
if ($classPath == null) {
require_once 'creole/Creole.php';
} else {
require_once $classPath;
}
// set our flags
$noAssocLower = $this->getParameter('no_assoc_lower', false);
$persistent = $this->getParameter('persistent', false);
$compatAssocLower = $this->getParameter('compat_assoc_lower', false);
$compatRtrimString = $this->getParameter('compat_rtrim_string', false);
$flags = 0;
$flags |= $noAssocLower ? Creole::NO_ASSOC_LOWER : 0;
$flags |= $persistent ? Creole::PERSISTENT : 0;
$flags |= $compatAssocLower ? Creole::COMPAT_ASSOC_LOWER : 0;
$flags |= $compatRtrimString ? Creole::COMPAT_RTRIM_STRING : 0;
// do the duuuurtay work, right thurr
if ($flags > 0) {
$this->connection = Creole::getConnection($dsn, $flags);
} else {
$this->connection = Creole::getConnection($dsn);
}
// get our resource
$this->resource = $this->connection->getResource();
} catch (SQLException $e) {
// the connection's foobar'd
throw new sfDatabaseException($e->toString());
}
}
示例12: array_merge
$_SESSION = array_merge($_SESSION, $arraySession);
//Required classes for dbArray work
//require_once ("propel/Propel.php");
//require_once ("creole/Creole.php");
//G::LoadThirdParty ("pake", "pakeColor.class");
Propel::init (PATH_CORE . "config/databases.php");
Creole::registerDriver ('dbarray', 'creole.contrib.DBArrayConnection');
function getLangFiles()
{
$dir = PATH_LANGUAGECONT;
$filesArray = array ();
if (file_exists ($dir)) {
if ($handle = opendir ($dir)) {
示例13: getConnection
/**
*
* @param string $name The database name.
* @return Connection A database connection
* @throws PropelException - if no conneciton params, or SQLException caught when trying to connect.
*/
public static function getConnection($name = null)
{
if ($name === null) {
$name = self::getDefaultDB();
}
$con = isset(self::$connectionMap[$name]) ? self::$connectionMap[$name] : null;
if ($con === null || $name === 'dbarray') {
$dsn = isset(self::$configuration['datasources'][$name]['connection']) ? self::$configuration['datasources'][$name]['connection'] : null;
if ($dsn === null) {
if (isset($_SESSION['PROCESS'])) {
/** Added By Erik Amaru <erik@colosa.com *******************************
* @date: 27-05-08 11:48 *
* @Description: this was added for the additional database connections *
***********************************************************************/
G::LoadClass('dbConnections');
$oDbConnections = new dbConnections($_SESSION['PROCESS']);
$oDbConnections->loadAdditionalConnections();
$dsn = isset(self::$configuration['datasources'][$name]['connection']) ? self::$configuration['datasources'][$name]['connection'] : null;
} else {
throw new PropelException("No connection params set for " . $name);
}
}
include_once 'creole/Creole.php';
// if specified, use custom driver
if (isset(self::$configuration['datasources'][$name]['driver'])) {
Creole::registerDriver($dsn['phptype'], self::$configuration['datasources'][$name]['driver']);
}
try {
$con = Creole::getConnection($dsn);
} catch (SQLException $e) {
throw new PropelException($e);
}
self::$connectionMap[$name] = $con;
}
return $con;
}
示例14: main
/**
* Iterates through each datamodel/database, dumps the contents of all tables and creates a DOM XML doc.
*
* @return void
* @throws BuildException
*/
public function main()
{
$this->validate();
$buf = "Database settings:\n" . " driver: " . ($this->databaseDriver ? $this->databaseDriver : "(default)") . "\n" . " URL: " . $this->databaseUrl . "\n" . ($this->databaseUser ? " user: " . $this->databaseUser . "\n" : "") . ($this->databasePassword ? " password: " . $this->databasePassword . "\n" : "");
// deprecated
$this->log($buf, PROJECT_MSG_VERBOSE);
// 1) First create the Data XML -> database name map.
$this->createDataDbMap();
// 2) Now go create the XML files from teh database(s)
foreach ($this->getDataModels() as $dataModel) {
// there is really one 1 db per datamodel
foreach ($dataModel->getDatabases() as $database) {
// if database name is specified, then we only want to dump that one db.
if (empty($this->databaseName) || $this->databaseName && $database->getName() == $this->databaseName) {
$outFile = $this->getMappedFile($dataModel->getName());
$this->log("Dumping data to XML for database: " . $database->getName());
$this->log("Writing to XML file: " . $outFile->getName());
try {
$url = str_replace("@DB@", $database->getName(), $this->databaseUrl);
$buf = "Database settings:\n" . " driver: " . ($this->databaseDriver ? $this->databaseDriver : "(default)") . "\n" . " URL: " . $url . "\n" . ($this->databaseUser ? " user: " . $this->databaseUser . "\n" : "") . ($this->databasePassword ? " password: " . $this->databasePassword . "\n" : "");
$this->log($buf, PROJECT_MSG_VERBOSE);
$dsn = Creole::parseDSN($url);
// deprecated, but here for BC
if ($this->databaseUser) {
$dsn['username'] = $this->databaseUser;
}
if ($this->databasePassword) {
$dsn['password'] = $this->databasePassword;
}
if ($this->databaseName) {
$dsn['database'] = $this->databaseName;
}
if ($this->databaseDriver) {
Creole::registerDriver($dsn['phptype'], $this->databaseDriver);
}
$this->conn = Creole::getConnection($dsn);
$doc = $this->createXMLDoc($database);
$doc->save($outFile->getAbsolutePath());
} catch (SQLException $se) {
$this->log("SQLException while connecting to DB: " . $se->getMessage(), PROJECT_MSG_ERR);
throw new BuildException($se);
}
}
// if databaseName && database->getName == databaseName
}
// foreach database
}
// foreach datamodel
}
示例15: getConnection
/**
*
* @param string $name The database name.
* @return Connection A database connection
* @throws PropelException - if no conneciton params, or SQLException caught when trying to connect.
*/
public static function getConnection($name = null)
{
if ($name === null || $name != self::$configuration['datasources']['default']) {
$name = self::getDefaultDB();
}
$con = isset(self::$connectionMap[$name]) ? self::$connectionMap[$name] : null;
if ($con === null) {
$dsn = isset(self::$configuration['datasources'][$name]['connection']) ? self::$configuration['datasources'][$name]['connection'] : null;
if ($dsn === null) {
throw new PropelException("No connection params set for " . $name);
}
include_once 'creole/Creole.php';
// if specified, use custom driver
if (isset(self::$configuration['datasources'][$name]['driver'])) {
Creole::registerDriver($dsn['phptype'], self::$configuration['datasources'][$name]['driver']);
}
try {
$con =& Creole::getConnection($dsn);
} catch (SQLException $e) {
throw new PropelException($e);
}
self::$connectionMap[$name] = $con;
}
return $con;
}