读取一行数据集, 此函数的别名函数 getRowByCmd
public array findOne(string $sql [, array $bind_value = array() [, int $fetch_style = PDO::FETCH_ASSOC]])
SQL 语句
把一个值绑定到一个参数
设置 fetch_style; 默认 int fetch_style = PDO::FETCH_ASSOC
只有一种返回结果类型 Array, 无值时返回空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 $sql = "SELECT * FROM qvr"; print_r($mysql->findOne($sql));
<?php $sql = "SELECT * FROM qvr WHERE id = ? AND pp = ?"; $value = ['36', '1']; print_r($mysql->findOne($sql, $value));
<?php $sql = "SELECT * FROM qvr WHERE id = ? AND pp = ?"; $value = ['36', '1']; print_r($mysql->findOne($sql, $value, PDO::FETCH_OBJ));
<?php $sql = "SELECT * FROM qvr WHERE pp LIKE ?"; $value = ['%zh%']; print_r($mysql->findOne($sql, $value));
<?php $sql = "SELECT * FROM qvr LIMIT 1"; $value = []; print_r($mysql->findOne($sql, $value, PDO::FETCH_OBJ));