Asf_Db_Adapter_Mysql


Introduction

Asf_Db_Adapter_Mysql Connecting to MySQL databases

在开启命名空间情况下(asf.use_namespace=1)类名为 Asf\Db\Adapter\Mysql

Class synopsis

<?php
final class Asf_Db_Adapter_Mysql extends Asf_Db_AbstractAdapter
{
    protected $_type = 'mysql';
}

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);

Examples

Example #1 采用实例化对象方式, 连接MySQL DB

<?php
$mysql = new Asf_Db_Adapter_Mysql($configs);
print_r($mysql);

Example #2 查询一条记录集

<?php
$mysql = new Asf_Db_Adapter_Mysql($configs);
$mysql->findOne("SELECT * FROM table where id = 1");

Example #3 PDOStatement::debugDumpParams()

<?php
$mysql = new Asf_Db_Adapter_Mysql($configs);
$dbh = $mysql->prepare("SELECT * FROM table where id = 1");
print_r($dbh->debugDumpParams());

Example #4 采用静态方式, 连接DB

<?php
Asf_Db::init($configs);

Example #5 采用静态方式, 连接MySQL DB

<?php
Asf_Db::initMySQL($configs)