Asf_Db_AbstractAdapter::findOneBy

读取一行数据集


Description

public array findOneBy(array $data [, array $fields = array() [, int $fetch_style = PDO::FETCH_ASSOC]])

Parameters

data

需要一个关联数组 key => value 键值对

fields

只需要一个索引数组

fetch_style

为语句设置默认的获取模式; 默认 int fetch_style = PDO::FETCH_ASSOC

Return Values

有子元素 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
$pairs = array('id' => "13", 'user' => 'lisi');
$mysql->findOneBy($pairs);

Example #2

<?php
// SELECT `user`, `pass` FROM `test1` WHERE `id` = 13 AND `user` = 'lisi'
$pairs = array('id' => "13", 'user' => 'lisi');
$mysql->findOneBy($pairs, array('user', 'pass'));

Example #3

<?php
// SELECT * FROM `test1` WHERE `id` = 13 AND `user` = 'lisi'
$pairs = array('id' => "13", 'user' => 'lisi');
$mysql->findOneBy($pairs);

Example #4 fetch_style = PDO::FETCH_OBJ

<?php
// SELECT * FROM `test1` WHERE `id` = 13 AND `user` = 'lisi'
$pairs = array('id' => "13", 'user' => 'lisi');
$mysql->findOneBy($pairs, array('user', 'pass'), PDO::FETCH_OBJ);