$sql = 'SELECT name, colour, calories
    FROM fruit
    WHERE calories < :calories AND colour = :colour';
$sth $dbh->prepare($sqlarray(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$sth->execute(array(':calories' => 150, ':colour' => 'red'));
$red $sth->fetchAll();
$sth->execute(array(':calories' => 175, ':colour' => 'yellow'));
$yellow $sth->fetchAll();
1
2
3
4
5
6
7
$sth $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?');
$sth->execute(array(150, 'red'));
$red $sth->fetchAll();
$sth->execute(array(175, 'yellow'));
$yellow $sth->fetchAll();

总结地址:http://www.cnblogs.com/pinocchioatbeijing/archive/2012/03/20/2407869.html

http://sjolzy.cn/PDO-query-results-achieved-in-many-ways.html

无论原来数据库里的数据是什么类型,通过这写遍历方法出来的数组,里面的成员都成了字符串 ? var_dump一下,发现全是string......

If you want to use PDO::FETCH_CLASS but don't like that all the values are of the type string, you can always use the __construct function of the class specified to convert them to a different type.

Another way is using mysqlnd, but it seems I had to recompile PHP for that.

<?php

class Cdr {
    public $a; // int
    public $b; // float
    public $c; // string
    
    public function __construct() {
        $this->a = intval($this->a);
        $this->b = floatval($this->b);
    }
     
}

// ...
$arrCdrs = $objSqlStatement->fetchAll(PDO::FETCH_CLASS, 'Cdr');

?>

 setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

发现填上这句话后,fetchall得来的类型是正确的。

如果没有这句话,fetchall得来的都是字符串

PDO 指南

http://www.oschina.net/translate/php-pdo-how-to

PHP pdao用法总结的更多相关文章

  1. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  2. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  3. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  4. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  5. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

  6. [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...

  7. 【JavaScript】innerHTML、innerText和outerHTML的用法区别

    用法: <div id="test">   <span style="color:red">test1</span> tes ...

  8. chattr用法

    [root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...

  9. 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)

    vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...

随机推荐

  1. 记录一些容易忘记的属性 -- UIKeyboard

    //UIKeyboardWillShowNotification这个通知在软键盘弹出时由系统发送    //UIKeyboardWillShowNotification 通知:键盘将要显示的通知    ...

  2. Struts2 和 spring mvc的 迭代标签常用属性对比

    <s:iterator value="#users" var="u" status="st"> <c:forEach  i ...

  3. jsunit测试

    var script = document.createElement('script'); script.src = 'http://static.pay.baidu.com/resource/ba ...

  4. HTML的盒子模型

    每个HTML元素都可以看作一个装了东西的盒子,盒子具有宽度(width)和高度(height),盒子里面的内容到盒子的边框之间的距离即填充(padding),盒子本身有边框(border),而盒子边框 ...

  5. CSS样式选择器

    <!-- css样式选择器 HTML选择器 类选择器 ID选择器 关联选择器 组合选择器 伪元素选择器 selector{ /* selector是样式选择器 property:value; / ...

  6. 【LEETCODE OJ】Candy

    Problem link: http://oj.leetcode.com/problems/candy/ Suppose we are given an array R[1..N] that are ...

  7. swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...

  8. python 各种控制语句

    python的控制语句分为: if: if condition: cmd elif condition:#该块为可选 cmd else:#该块为可选 cmd while: whlie conditio ...

  9. 《JS高程》数据类型学习笔记

    认认真真看完了<JavaScript高级程序设计>第3章的基本概念,原来一直不明白的知识点都在这里面啊...T_T...基础真的很重要,很重要,很重要... 现在终于明白了读书的技巧,书读 ...

  10. CSS知识点总结

    1.选择器 参考链接:十分钟搞定CSS选择器-Samaritans  CSS选择器笔记-阮一峰  CSS选择器-w3school  MDN 参考书籍:<CSS高效开发指南> 2.布局 2. ...