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


PHP pdo::setAttribute方法代码示例

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


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

示例1: dbConnect

function dbConnect($timeout, $options = array())
{
    $db = new pdo(PDO_dsn, PDO_username, PDO_password);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    $db->setAttribute(PDO::ATTR_TIMEOUT, "0");
    foreach ($options as $option) {
        $db->exec($option);
    }
    return $db;
}
开发者ID:blublud,项目名称:SocialCrawler,代码行数:10,代码来源:pdoReconnect.php

示例2: getDb

 /**
  * Get Database PDO connection
  * @param - no param
  * @return pdo
  */
 public function getDb()
 {
     if (self::$pdo == null) {
         $dsn = DBENGINE . ':dbname=' . DATABASE . ';host=' . HOST . ';portname=' . PORTNAME . ';';
         try {
             self::$pdo = new PDO($dsn, USERNAME, PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
             //Enabling exceptions
             self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             echo $e->getMessage();
         }
     }
     return self::$pdo;
 }
开发者ID:asbag,项目名称:WebServicesRestful,代码行数:19,代码来源:Database.php

示例3: connect

 /**
  * 创建pdo实例
  */
 protected function connect()
 {
     $dsn = 'mysql:dbname=' . $this->settings["dbname"] . ';host=' . $this->settings["host"] . ';port=' . $this->settings['port'];
     $this->pdo = new \PDO($dsn, $this->settings["user"], $this->settings["password"], array(\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . (!empty($this->settings['charset']) ? $this->settings['charset'] : 'utf8')));
     $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
 }
开发者ID:qycloud,项目名称:ant_utils,代码行数:10,代码来源:DbConnection.php

示例4: sprintf

<?php

echo "this is a database test.";
$ip = '192.168.33.61';
$port = '3306';
$user = 'root';
$pass = '';
$info = sprintf("mysql:host=%s;port=%s,database=;", $ip, $port);
$db = new pdo($info, $user, $pass, array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$sth = $db->query('use test_database');
$sth = $db->prepare('select * from fukens');
$sth->execute(array());
while ($line = $sth->fetch()) {
    var_dump($line);
}
exit;
开发者ID:niwakazuki,项目名称:shop_cart,代码行数:18,代码来源:pdo.php

示例5: pdo

<?php

try {
    $con = new pdo('mysql:host=localhost;dbname=test', 'root', '');
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo $e->getMessage();
    die;
}
开发者ID:afiqiqmal,项目名称:Web,代码行数:9,代码来源:config.php

示例6: get_db_connection

function get_db_connection()
{
    $db = new pdo(DB_DRIVER . ":dbname=" . DB_NAME . ";charset=utf8;host=" . DB_HOST, DB_USER, DB_PASS);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    return $db;
}
开发者ID:sewede,项目名称:wetzel.work,代码行数:6,代码来源:getTechs.php

示例7: execute

 /**
  * Executes sql statement without any return value. Please consider the usage of 
  * prepared statements which is fully supported.
  *
  * <code>
  * <?php
  * dbConn::execute("INSERT INTO :prefix:user (username, registered) VALUES (:0, :1);", 'felix', (new DateTime));
  * ?>
  *
  * @param 	string 				$query The query in sql language.
  * @param 	multiple strings 	The values that will fill the variables in the query.
  * @static
  */
 public static function execute()
 {
     $argsCount = func_num_args();
     $par = array();
     // no query as parameter given
     if ($argsCount < 1) {
         throw new Exception("No Sql-Query given");
     }
     // if there are parameters, insert in
     if ($argsCount > 1) {
         // create array with parameters for pdo usage
         for ($i = 1; $i < $argsCount; $i++) {
             $key = ":" . ($i - 1);
             $par[$key] = func_get_arg($i);
         }
     }
     // insert table prefix
     $query = func_get_arg(0);
     $query = str_replace(":prefix:", dbConn::$tablePrefix, $query);
     // create pdo connection
     $db = new pdo("mysql:" . "host=" . dbConn::$host . ";" . "dbname=" . dbConn::$database . ";" . "charset=UTF8", dbConn::$username, dbConn::$password);
     $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     try {
         // prepare and execute
         $sth = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
         if (!$sth) {
             throw new Exception($db->errorInfo());
         }
         $sth->execute($par);
     } catch (Exception $ex) {
         throw new Exception($ex->getMessage());
     }
     // close database connection
     $db = null;
 }
开发者ID:fhoner,项目名称:smartdoorbell,代码行数:48,代码来源:dbConn.php


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