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


PHP Db::pdo方法代码示例

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


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

示例1: getPDO

 /**
  *   Erstellt ein PDO Objekt
  *
  * @return PDO pdo
  */
 public static function getPDO()
 {
     if (self::$pdo == null) {
         $config = Config::getArray();
         if (!isset($config["database"])) {
             Helpers::fatalError("No database configuration found.");
         }
         $host = '';
         if (isset($config['database']['host'])) {
             $host = 'host=' . $config['database']['host'] . ';';
         }
         $port = '';
         if (isset($config['database']['port'])) {
             $port = 'port=' . $config['database']['port'] . ';';
         }
         $socket = '';
         if (isset($config['database']['socket'])) {
             $socket = 'unix_socket=' . $config['database']['socket'] . ';';
         }
         $dsn = 'mysql:dbname=' . $config["database"]["name"] . ';' . $host . $port . $socket . 'charset=utf8;';
         try {
             $pdo = new PDO($dsn, $config["database"]["user"], $config["database"]["password"], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
         } catch (PDOException $e) {
             Helpers::fatalError("Could no connect to the database: " . $e->getMessage());
         }
         self::$pdo = $pdo;
     }
     return self::$pdo;
 }
开发者ID:pixelproduction,项目名称:PixelManagerCMS,代码行数:34,代码来源:Db.php

示例2: getDb

 public static function getDb()
 {
     if (!isset(self::$pdo)) {
         self::$pdo = new Pdo(Connection::$connectionString, Connection::$username, Connection::$password);
     }
     return self::$pdo;
 }
开发者ID:apogza,项目名称:Anesthesia,代码行数:7,代码来源:Db.php

示例3: getInstance

 public static function getInstance()
 {
     if (is_null(self::$pdo)) {
         self::$pdo = new PDO(sprintf('%s:host=%s; port=%d; dbname=%s; charset=utf8;', 'mysql', 'localhost', 3306, 'cat'), 'cat', 'cat');
         self::$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
     }
     return self::$pdo;
 }
开发者ID:octps,项目名称:cat,代码行数:8,代码来源:Db.php

示例4: init

 public static function init()
 {
     if (self::$pdo === null) {
         self::$pdo = new \PDO('mysql:host=127.0.0.1;dbname=testdb;charset=utf8', 'user', 'login');
     }
     if (self::$pdo instanceof \PDO) {
         return true;
     }
     return false;
 }
开发者ID:spendlively,项目名称:mydictionary,代码行数:10,代码来源:Db.php

示例5: connect

 /**
  * Connects to database
  * All the parameters could also be set in config file:
  *
  * 		'db_dsn'		=> 'mysql:dbname=bakedcarrot;host=localhost',
  *      'db_username' 	=> 'db_user',
  *      'db_password' 	=> 'db_password',
  *      'db_charset' 	=> 'utf8',
  *
  * @static
  * @param null $dsn DSN in PDO format
  * @param null $username username to connect to database server
  * @param null $password connection password
  * @param string $charset default character set
  * @return void
  * @throws BakedCarrotDbException
  */
 public static function connect($dsn = null, $username = null, $password = null, $charset = 'utf8')
 {
     if (!is_null(self::$pdo) && !$dsn) {
         return;
     } elseif (!is_null(self::$pdo) && $dsn) {
         self::$pdo = null;
     }
     if (!$dsn) {
         if (!Config::checkVar('db_dsn')) {
             throw new BakedCarrotDbException('Database access parameters are not properly configured');
         }
         $dsn = Config::getVar('db_dsn');
         $username = Config::getVar('db_username');
         $password = Config::getVar('db_password');
         $charset = Config::getVar('db_charset', 'utf8');
     }
     self::$pdo = new DbPDO($dsn, $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::MYSQL_ATTR_INIT_COMMAND => 'set names ' . $charset, PDO::ATTR_AUTOCOMMIT => true));
     Log::out(__METHOD__ . ' Connected to: "' . $dsn . '"', Log::LEVEL_DEBUG);
 }
开发者ID:nicksp,项目名称:BakedCarrot,代码行数:36,代码来源:Db.php

示例6: pdoConnect

 /**
  * Actually makes a connection to the database (by creating a PDO instance)
  * @param array $modifications
  *  The modifications to the connection info, if any.
  *  Can contain the keys "dsn", "username", "password", "driver_options"
  *  They are used in constructing the PDO object.
  */
 function pdoConnect($modifications = array())
 {
     if ($this->pdo) {
         return;
     }
     if (!isset($modifications)) {
         $modifications = array();
     }
     $conn_name = $this->conn_name;
     $conn_info = Db::getConnection($conn_name);
     if (empty($conn_info)) {
         throw new Exception("Database connection \"{$conn_name}\" wasn't registered with Db.", -1);
     }
     if (!isset($conn_info['driver_options'])) {
         $conn_info['driver_options'] = null;
     }
     $dsn = isset($modifications['dsn']) ? $modifications['dsn'] : $conn_info['dsn'];
     $username = isset($modifications['username']) ? $modifications['username'] : $conn_info['username'];
     $password = isset($modifications['password']) ? $modifications['password'] : $conn_info['password'];
     $driver_options = isset($modifications['driver_options']) ? $modifications['driver_options'] : $conn_info['driver_options'];
     $this->pdo = Db::pdo($dsn, $username, $password, $driver_options);
     $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
开发者ID:EGreg,项目名称:PHP-On-Pie,代码行数:30,代码来源:Mysql.php

示例7: session_start

<?php

session_start();
require_once $_SERVER['DOCUMENT_ROOT'] . '/Db.php';
$db = Db::pdo();
print_r($_SESSION);
$email = $_SESSION['email'];
$statement = $db->prepare("UPDATE user_details SET login_state = '0' WHERE email = '{$email}'");
$statement->execute();
$id = $_SESSION['id'];
$statement = $db->prepare("UPDATE user_details SET login_state = '0' WHERE id = '{$id}'");
$statement->execute();
session_unset();
header('Location: http://www.tradeyokickz.com/');
开发者ID:NRassoules,项目名称:TradeYoKickz,代码行数:14,代码来源:Logout.php

示例8: save

 /**
  * insert or update modified object data into self::$table and any associated metadata
  *
  * @return void
  */
 public function save()
 {
     if (empty($this->changed)) {
         return;
     }
     $data = array_intersect_key($this->data, $this->changed);
     // use proper sql NULL for values set to php null
     foreach ($data as $key => $value) {
         if ($value === null) {
             $data[$key] = new PlainSql('NULL');
         }
     }
     if ($this->id) {
         $query = 'update `' . static::$table . '` set `' . implode('` = ?, `', array_keys($data)) . '` = ? where `' . static::$pk . '` = ' . $this->id . ' limit 1';
     } else {
         $query = 'insert into `' . static::$table . '` (`' . implode('`,`', array_keys($data)) . "`) values (" . rtrim(str_repeat('?,', count($data)), ',') . ")";
     }
     Db::execute($query, array_values($data));
     if ($this->id === null) {
         $this->id = Db::pdo()->lastInsertId();
     }
     $this->meta->{'set' . Builder::camelCase(static::$meta_field)}($this->id)->save();
     $this->hydrate(self::one(array(static::$pk => $this->id))->toArray());
 }
开发者ID:jasonmoo,项目名称:DumbledORM,代码行数:29,代码来源:dumbledorm.php

示例9: log

            self::$fails++;
            return self::log(" Failed!\n");
        }
        self::log(" Success.\n");
    }
    private static function log($message)
    {
        echo $message;
    }
}
try {
    $db = mysql_connect(DbConfig::HOST, DbConfig::USER, DbConfig::PASSWORD);
    mysql_query("drop database if exists {$dbname}", $db);
    mysql_query("create database {$dbname}", $db);
    mysql_close($db);
    Db::pdo();
    OrmTest::assertTrue("Creating test database {$dbname}.", true);
} catch (Exception $e) {
    throw new OrmTestException('Unable to create test database.  Probably missing proper config.php or a permissions issue. (' . $e->getMessage() . ')');
}
try {
    Db::execute("CREATE TABLE `{$dbname}`.`user` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `name` varchar(255) NOT NULL,\n    `email` varchar(255) NOT NULL,\n    `active` tinyint(4) NOT NULL,\n    `created_at` datetime NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
    Db::execute("CREATE TABLE `{$dbname}`.`phone_number` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `user_id` int(11) NOT NULL,\n    `number` varchar(255) NOT NULL,\n    `type` varchar(255) NOT NULL,\n    `location` varchar(255),\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    Db::execute("CREATE TABLE `{$dbname}`.`post` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `user_id` int(11) NOT NULL,\n    `title` varchar(255) NOT NULL,\n    `body` text NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    Db::execute("CREATE TABLE `{$dbname}`.`post_meta` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `post_id` int(11) NOT NULL,\n    `key` varchar(255) NOT NULL,\n    `val` varchar(255) NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    Db::execute("CREATE TABLE `{$dbname}`.`orphan` (\n    `id` int(11) NOT NULL AUTO_INCREMENT,\n    `name` varchar(255) NOT NULL,\n    `age` varchar(255) NOT NULL,\n    PRIMARY KEY (`id`)\n  ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
    OrmTest::assertTrue("Creating test database tables.", true);
} catch (Exception $e) {
    throw new OrmTestException('Unable to create test tables.  Probably a permissions issue. (' . $e->getMessage() . ')');
}
try {
开发者ID:jasonmoo,项目名称:DumbledORM,代码行数:31,代码来源:test.php


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