2017 © Pedro Peláez
 

project db-connection

PDO Connection

image

aweitian/db-connection

PDO Connection

  • Friday, May 11, 2018
  • by awei.tian
  • Repository
  • 1 Watchers
  • 0 Stars
  • 68 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 11 % Grown

The README.md

PDO Connection组件

安装组件

使用 composer 命令进行安装或下载源代码使用。, (*1)

composer require aweitian/connection, (*2)

//参数错误出抛出异常
new Aw\Db\Connection\Mysql ( [ 
    'host' => '127.0.0.1',
    'port' => 3306,
    'user' => 'root',
    'password' => 'root',
    'charset' => 'utf8',
    'database' => 'garri' 
] );

设置调试模式

/**
 * 
 * 设置为TRUE。异常由PDO对象抛出
 * 默认为FALSE,异常由MysqlPdoConn对象抛出
 */
function setDebugMode($mode);

连接信息获取

getDbName();  #返回数据库名
getHost();    #返回主机名
getCharset(); #返回连接端口

添加记录

/**
 *
 * 当主键是自增时,返回插入ID,其它返回0
 * 有错误时会抛出异常
 * @param string $sql           
 * @param array $data       eg: ['k' => 'v','a' => 'b']         
 * @param array $bindType   KEY和DATA一样,值为PDO:PARAM_**
 * @return int
 */
insert($sql, $data = [], $bindType = []);

获取一个数据

/**
 *
 * 返回一个标量
 * @param string $sql           
 * @param array $data           
 * @return mixed;
 */
public function scalar($sql, $data = [], $bindType = [])

获取一行数据

/**
 *
 * 返回一维数组,SQL中的结果集中的第一个元组
 * 有错误时会抛出异常
 * @param string $sql           
 * @param array $data           
 * @return array;
 */
public function fetch($sql, $data = [], $bindType = [], $fetch_mode = \PDO::FETCH_ASSOC)

获取表格数据

/**
 *
 * 返回二维数组
 * 有错误时会抛出异常
 * @param string $sql           
 * @param array $data           
 * @return array;
 */
public function fetchAll($sql, $data = [], $bindType = [], $fetch_mode = \PDO::FETCH_ASSOC)

SQL执行操作,可多条语句同时执行

/**
 *
 * 返回影响行数
 * 有错误时会抛出异常
 * @param string $sql           
 * @param array $data           
 * @param array $bindType
 *          KEY和DATA一样,值为PDO:PARAM_**
 * @return int
 */
public function exec($sql, $data = [], $bindType = [])

事务

function transaction(\Closure $closure) #返回对象本身
function beginTransaction() #返回对象本身
function rollback()         #返回对象本身
function commit()           #返回对象本身
function getQueryLog()      #返回对象本身

The Versions

11/05 2018

dev-master

9999999-dev https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

11/05 2018

v2.0.5

2.0.5.0 https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

11/05 2018

v2.0.4

2.0.4.0 https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

28/03 2018

v2.0.3

2.0.3.0 https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

28/03 2018

v2.0.2

2.0.2.0 https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

28/03 2018

v2.0.1

2.0.1.0 https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

24/01 2018

v2.0.0

2.0.0.0 https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

25/09 2017

dev-dev

dev-dev https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei

28/05 2017

v1.0

1.0.0.0 https://github.com/aweitian/db-connection

PDO Connection

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by awei.tian@qq.com

dbconnection aweitian tiananwei