PHP pdao用法总结
$sql = 'SELECT name, colour, calories FROM fruit WHERE calories < :calories AND colour = :colour';$sth = $dbh->prepare($sql, array(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');
?>
发现填上这句话后,fetchall得来的类型是正确的。
如果没有这句话,fetchall得来的都是字符串
PDO 指南
http://www.oschina.net/translate/php-pdo-how-to
PHP pdao用法总结的更多相关文章
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
- [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...
- 【JavaScript】innerHTML、innerText和outerHTML的用法区别
用法: <div id="test"> <span style="color:red">test1</span> tes ...
- chattr用法
[root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...
- 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)
vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...
随机推荐
- iOS中类方法的作用
类方法,这意味着你将它发送给类,而不是对象实例. 因为不是发送给一个实例,所以你不能使用任何实例变量,你只能做一些通用性的事情. 实际上类方法只用于两种情况: 1.创建事物,比如创建一个特殊格式的字符 ...
- LOGISTIC REGRESSION
In logistic regression we learn a family of functions
- 简单的两数之和再次乱入<< Add Two Numbers >>
请看题目描述: You are given two linked lists representing two non-negative numbers. The digits are stored ...
- JS constructor
1.每个对象都有一个constructor,都指向创建该对象的方法. 2.function对象的prototype的constructor也是指向该方法.如果对prototype进行重写,constr ...
- Ubuntu 14.10 下网络流量实时监控ifstat iftop命令详解
ifstat 介绍 ifstat工具是个网络接口监测工具,比较简单看网络流量 实例 默认使用 #ifstat eth0 eth1 KB/s in KB/s out KB/s in KB/s out 0 ...
- Oracle之ROW_NUMBER() OVER函数
语法:ROW_NUMBER() OVER(ORDER BY COLUMN) 简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的select ACD_ID,ROW_NUMBE ...
- (转)IOS之Info.plist文件简介
原文:IOS之Info.plist文件简介 http://www.apkbus.com/android-130240-1-1.html (出处: Android开发论坛 - 安卓开发论坛 - Andr ...
- hdu 2082
ps:get到了母函数...看了好久的模板与介绍....似懂非懂..决定要多找些题来试试... 代码: #include "stdio.h" #include "stri ...
- LeetCode---Word Break 2
Given a string s and a dictionary of wordsdict, add spaces in s to construct a sentence where each w ...
- POJ 3278 经典BFS
进一步了解了bfs; 题意:给你n,然后用+,-,*三种运算使n变成k; 漏洞:在算出新的数字之后,一定要判边界,否则RE,而且在每一步后面都得加判断是否等于K,如果是即刻退出,否则WA,判这个的时候 ...