Asf_Db_AbstractAdapter::findAll

读取全部数据集, 此函数的别名函数 getRowsByCmd


Description

public array findAll(string $sql [, array $bind_value = array() [, int $fetch_style = PDO::FETCH_ASSOC]])

Parameters

sql

SQL 语句

bind_value

把一个值绑定到一个参数

fetch_style

设置 fetch_style; 默认值 int fetch_style = PDO::FETCH_ASSOC

Return Values

只有一种返回结果类型 Array, 无值时返回空Array

Examples

Connect MySQL Database

<?php
$configs = array(
    'dsn' => array('host' => '127.0.0.1', 'dbname' => 'test', 'port' => 6666),
    'username' => 'test',
    'password' => 'AbcdefRDvgedf',
);

$mysql = new Asf_Db_Adapter_Mysql($configs);
$mysql->setTableName('test1');

Example #1

<?php
$sql = "select * from qvr";
print_r($mysql->findAll($sql));
print_r($mysql->findAll($sql, array()));

Example #2

<?php
$sql = "select * from qvr where id = ? and pid = ?";
$value = array('36', '1');
print_r($mysql->findAll($sql, $value));

Example #3 int fetch_style = PDO::FETCH_BOTH

<?php
$sql = "select * from qvr where id = ? and pid = ?";
$value = array('36', '1');
print_r($mysql->findAll($sql, $value, PDO::FETCH_BOTH));

Example #4 模糊查询

<?php
$sql = "select * from qvr where name like ?";
$value = array('%zh%');
print_r($mysql->findAll($sql, $value));