读取一行数据集
public array findOneBy(array $data [, array $fields = array() [, int $fetch_style = PDO::FETCH_ASSOC]])
需要一个关联数组 key => value 键值对
只需要一个索引数组
为语句设置默认的获取模式; 默认 int fetch_style = PDO::FETCH_ASSOC
有子元素 Array 代表成功, 空数组代表失败
<?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');
<?php $pairs = array('id' => "13", 'user' => 'lisi'); $mysql->findOneBy($pairs);
<?php // SELECT `user`, `pass` FROM `test1` WHERE `id` = 13 AND `user` = 'lisi' $pairs = array('id' => "13", 'user' => 'lisi'); $mysql->findOneBy($pairs, array('user', 'pass'));
<?php // SELECT * FROM `test1` WHERE `id` = 13 AND `user` = 'lisi' $pairs = array('id' => "13", 'user' => 'lisi'); $mysql->findOneBy($pairs);
<?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);