PHP code example of aweitian / db-connection

1. Go to this page and download the library: Download aweitian/db-connection library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aweitian / db-connection example snippets


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

/**
 *
 * 当主键是自增时,返回插入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)

/**
 *
 * 返回影响行数
 * 有错误时会抛出异常
 * @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()      #返回对象本身