Asf_Db_AbstractAdapter::findOne

读取一行数据集, 此函数的别名函数 getRowByCmd


Description

public array findOne(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->findOne($sql));

Example #2

<?php
$sql = "SELECT * FROM qvr WHERE id = ? AND pp = ?";
$value = ['36', '1'];
print_r($mysql->findOne($sql, $value));

Example #3 int fetch_style = PDO::FETCH_OBJ

<?php
$sql = "SELECT * FROM qvr WHERE id = ? AND pp = ?";
$value = ['36', '1'];
print_r($mysql->findOne($sql, $value, PDO::FETCH_OBJ));

Example #4 模糊查询

<?php
$sql = "SELECT * FROM qvr WHERE pp LIKE ?";
$value = ['%zh%'];
print_r($mysql->findOne($sql, $value));

Example #5

<?php
$sql = "SELECT * FROM qvr LIMIT 1";
$value = [];
print_r($mysql->findOne($sql, $value, PDO::FETCH_OBJ));