当前位置: 首页>>代码示例>>PHP>>正文


PHP Creole::getConnection方法代码示例

本文整理汇总了PHP中Creole::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP Creole::getConnection方法的具体用法?PHP Creole::getConnection怎么用?PHP Creole::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Creole的用法示例。


在下文中一共展示了Creole::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:robertkraig,项目名称:mycms,代码行数:11,代码来源:Database.php

示例2: 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();
 }
开发者ID:BackupTheBerlios,项目名称:php5cms-svn,代码行数:14,代码来源:OCI8ResultSetTest.php

示例3: 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();
 }
开发者ID:KimuraYoichi,项目名称:PukiWiki,代码行数:29,代码来源:creole.php

示例4: CreoleSessionContainer

 /**
  * Constructor
  */
 public function CreoleSessionContainer()
 {
     $this->conn = Creole::getConnection(Registry::get('__configurator')->getDatabaseDsn());
     CreoleSessionContainer::$lifetime = ini_get('session.gc_maxlifetime');
 }
开发者ID:BackupTheBerlios,项目名称:medick-svn,代码行数:8,代码来源:CreoleSessionContainer.php

示例5: 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;
 }
开发者ID:nmicht,项目名称:tlalokes-in-acst,代码行数:22,代码来源:PropelCreoleTransformTask.php

示例6: 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());
     }
 }
开发者ID:philippjenni,项目名称:icinga-web,代码行数:83,代码来源:AgaviCreoleDatabase.class.php

示例7: 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;
 }
开发者ID:nmicht,项目名称:tlalokes-in-acst,代码行数:31,代码来源:Propel.php

示例8: close_connection

 /**
  * Close the Database Connection
  */
 public static function close_connection()
 {
     ActiveRecord::$conn = Creole::getConnection(ActiveRecord::parse_dsn())->close();
 }
开发者ID:BackupTheBerlios,项目名称:medick-svn,代码行数:7,代码来源:Base.php

示例9: getConnection

 /**
  * Creates a new Connection as using the driver, url, userid and password specified.
  * The calling method is responsible for closing the connection.
  * @return Connection the newly created connection.
  * @throws BuildException if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.
  */
 protected function getConnection()
 {
     if ($this->url === null) {
         throw new BuildException("Url attribute must be set!", $this->location);
     }
     try {
         $this->log("Connecting to " . $this->getUrl(), PROJECT_MSG_VERBOSE);
         $info = new Properties();
         $dsn = Creole::parseDSN($this->url);
         if (!isset($dsn["username"]) && $this->userId === null) {
             throw new BuildException("Username must be in URL or userid attribute must be set.", $this->location);
         }
         if ($this->userId) {
             $dsn["username"] = $this->getUserId();
         }
         if ($this->password) {
             $dsn["password"] = $this->getPassword();
         }
         if ($this->driver) {
             Creole::registerDriver($dsn['phptype'], $this->driver);
         }
         $conn = Creole::getConnection($dsn);
         $conn->setAutoCommit($this->autocommit);
         return $conn;
     } catch (SQLException $e) {
         throw new BuildException($e->getMessage(), $this->location);
     }
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:34,代码来源:CreoleTask.php

示例10: connect

 /**
  *  DBに接続する
  *
  *  @access public
  *  @return mixed   0:正常終了 Ethna_Error:エラー
  */
 function connect()
 {
     $this->db = Creole::getConnection($this->dsn);
     return 0;
 }
开发者ID:BackupTheBerlios,项目名称:delphinus-svn,代码行数:11,代码来源:Ethna_DB_Creole.php

示例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());
     }
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:75,代码来源:sfCreoleDatabase.class.php

示例12: generate

    private function generate($name, $dsn)
    {
        $datasource = $name;
        $outputdir = dirname(__FILE__) . "/../../../components/entity";
        /*
         * start.
         */
        $conn = Creole::getConnection($dsn);
        $dbinfo = $conn->getDatabaseInfo();
        $base_dir = $outputdir . '/' . 'base';
        if (!file_exists($base_dir) && !mkdir($base_dir)) {
            print "could not make directory for base: {$outputdir}";
            exit;
        }
        foreach ($dbinfo->getTables() as $tbl) {
            $classname = "";
            $tablename = "";
            $capName = "";
            $pkdef = "";
            $coldef = "";
            $joindef = "";
            $aliasesdef = "";
            $tablename = strtolower($tbl->getName());
            $capName = $this->camelize($tablename);
            $classname = "Entity_{$capName}";
            $baseclassname = "Entity_Base_{$capName}";
            // columns
            $cols = array();
            foreach ($tbl->getColumns() as $col) {
                $cols[] = strtolower($col->getName());
            }
            // primary key
            $auto = 'FALSE';
            $pks = array();
            $pk = $tbl->getPrimaryKey();
            if (is_object($pk)) {
                foreach ($pk->getColumns() as $pkcol) {
                    $pks[] = strtolower($pkcol->getName());
                    if ($pkcol->isAutoIncrement()) {
                        $auto = 'TRUE';
                    }
                }
            }
            // join
            $aliases = array();
            $joindef_buf = array();
            $fks = $tbl->getForeignKeys();
            if (is_array($fks)) {
                foreach ($fks as $fk) {
                    $alias = "";
                    $entity = "";
                    $refdef = array();
                    $refs = $fk->getReferences();
                    if (is_array($refs)) {
                        //$alias = strtolower($fk->getName());
                        $alias = strtolower($refs[0][1]->getTable()->getName());
                        $entity = 'Entity_' . $this->camelize($refs[0][1]->getTable()->getName());
                        $aliases[] = array('name' => $alias, 'entity' => $entity);
                        foreach ($refs as $ref) {
                            $p = strtolower($ref[0]->getName());
                            $c = strtolower($ref[1]->getName());
                            $refdef[] = "                '{$p}' => '{$c}'";
                        }
                        $buf = "";
                        $buf .= "        '{$alias}' => array(\n";
                        $buf .= "            'entity' => '{$entity}',\n";
                        $buf .= "            'type' => 'INNER JOIN',\n";
                        $buf .= "            'relation' => array(\n";
                        $buf .= implode(",\n", $refdef);
                        $buf .= "\n";
                        $buf .= "            )\n";
                        $buf .= "        )";
                        $joindef_buf[] = $buf;
                    }
                }
            }
            if (count($joindef_buf)) {
                $joindef = implode(",\n", $joindef_buf);
            }
            if (count($aliases)) {
                foreach ($aliases as $alias) {
                    $aliasesdef .= <<<EOT
    /**
     * @var {$alias['entity']} 
     */
    public \${$alias['name']};


EOT;
                }
            }
            //$cols = array_diff($cols, $pks);
            foreach ($cols as $col) {
                $coldef .= "    public \$" . $col . ";\n";
            }
            //$coldef = "'". implode("',\n        '", $cols) ."'";
            $pkdef = "'" . implode("',\n'", $pks) . "'";
            // ベースクラスの作成
            $filepath = $outputdir . "/base/{$capName}.php";
            if (file_exists($filepath) && !$this->forceUpdate) {
//.........这里部分代码省略.........
开发者ID:miztaka,项目名称:teeple2,代码行数:101,代码来源:EntityGenerator.php

示例13: __construct

 public function __construct($dsn, $path = null)
 {
     $this->db = Creole::getConnection($dsn);
     $this->path = $path;
 }
开发者ID:saiber,项目名称:livecart,代码行数:5,代码来源:LiveCartImportDriver.php

示例14: testUnregisterDriver

 /**
  * Test to make sure that a de-registered driver cannot
  * be used.
  */
 public function testUnregisterDriver()
 {
     Creole::deregisterDriver('mysql');
     try {
         $driver = Creole::getConnection('mysql://hostname/dbname');
         $this->fail("Expected SQLException to be thrown by attempt to connect to unregistered driver type.");
     } catch (SQLException $e) {
         $this->expectException("No driver has been registered to handle connection type: mysql", $e);
     }
     // now put it back :)
     Creole::registerDriver('mysql', 'creole.drivers.mysql.MySQLConnection');
 }
开发者ID:BackupTheBerlios,项目名称:php5cms-svn,代码行数:16,代码来源:CreoleTest.php

示例15: insertDatabaseSqlFiles

 /**
  * Take the base url, the target database and insert a set of SQL
  * files into the target database.
  *
  * @param      string $url
  * @param      string $database
  * @param      array $transactions
  */
 private function insertDatabaseSqlFiles($url, $database, $transactions)
 {
     $url = str_replace("@DB@", $database, $url);
     $this->log("Our new url -> " . $url);
     try {
         $buf = "Database settings:\n" . " driver: " . ($this->driver ? $this->driver : "(default)") . "\n" . " URL: " . $url . "\n" . ($this->userId ? " user: " . $this->userId . "\n" : "") . ($this->password ? " password: " . $this->password . "\n" : "");
         $this->log($buf, PROJECT_MSG_VERBOSE);
         $dsn = Creole::parseDSN($url);
         if ($this->userId) {
             $dsn["username"] = $this->userId;
         }
         if ($this->password) {
             $dsn["password"] = $this->password;
         }
         if ($this->driver) {
             Creole::registerDriver($dsn['phptype'], $this->driver);
         }
         $this->conn = Creole::getConnection($dsn);
         $this->conn->setAutoCommit($this->autocommit);
         $this->statement = $this->conn->createStatement();
         $out = null;
         try {
             if ($this->output !== null) {
                 $this->log("Opening PrintStream to output file " . $this->output->__toString(), PROJECT_MSG_VERBOSE);
                 $out = new FileWriter($this->output);
             }
             // Process all transactions
             for ($i = 0, $size = count($transactions); $i < $size; $i++) {
                 $transactions[$i]->runTransaction($out);
                 if (!$this->autocommit) {
                     $this->log("Commiting transaction", PROJECT_MSG_VERBOSE);
                     $this->conn->commit();
                 }
             }
         } catch (Exception $e) {
             if ($out) {
                 $out->close();
             }
         }
     } catch (IOException $e) {
         if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
             try {
                 $this->conn->rollback();
             } catch (SQLException $ex) {
                 // do nothing.
                 System::println("Rollback failed.");
             }
         }
         if ($this->statement) {
             $this->statement->close();
         }
         throw new BuildException($e);
     } catch (SQLException $e) {
         if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
             try {
                 $this->conn->rollback();
             } catch (SQLException $ex) {
                 // do nothing.
                 System::println("Rollback failed");
             }
         }
         if ($this->statement) {
             $this->statement->close();
         }
         throw new BuildException($e);
     }
     $this->statement->close();
     $this->log($this->goodSql . " of " . $this->totalSql . " SQL statements executed successfully");
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:77,代码来源:PropelSQLExec.php


注:本文中的Creole::getConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。