pdo

注意:末尾的逗号分隔每个参数,同一个参数竖直着列出多条,选择其一。
/*---------------------------------------------*/

PDO {
__construct (    //初始化操作
            string $dsn 
            [, string $username 
            [, string $password 
            [, array $driver_options ::= array(
                                            PDO::ATTR_AUTOCOMMIT=>false, 
                                            PDO::ATTR_ERRMODE=>PDO::ERRMOD_EXCEPTION,
                                             ......   
                                          )
            ]]] )

/* 事务相关 */
bool beginTransaction ( void )  //开启一个事务,表名回滚起始点 $pdo->beginTransaction();
bool commit ( void )            //提交一个事务,并执行SQL     $pdo->commit()
bool rollBack ( void )           //回滚一个事务                $pdo->rollBack()
array inTransaction ( void )    //检测是否开启事务

/* 错误相关 */
mixed errorCode ( void )    //获取错误码    $pdo->errorCode();
array errorInfo ( void )  //获取错误信息   $pdo->errorInfo();

/* 查询相关 */
int exec ( string $sql )         //处理一个SQL语句,并返回所【影响的行数】。包括INSERT、DELETE、UPDATA
PDOStatement query ( string $sql ) //处理一个SQL语句,并返回一个"【PDOStatement】"对象 $stmt,用$stmt里的方法去处理结果集
PDOStatement prepare (   //★负责准备要执行SQL语句
                     string $sql 
                     [, array $driver_options = array() ] 
                     )
                     
PDO::string lastInsertId ([ string $name = NULL ] )  //获取插入到表中最后一条数据的主键值

/* 属性相关 */
array getAvailableDrivers ( void )   //获取有效的PDO驱动器名称
mixed getAttribute ( int $attribute )     //获取一个“数据库连接对象”的属性
                     (PDO::ATTR_AUTOCOMMIT) //自动提交
                     (PDO::ATTR_CASE)
                     (PDO::ATTR_CLIENT_VERSION)    //包含与数据库客户端版本号有关的信息
                     (PDO::ATTR_CONNECTION_STATUS) //包含与数据库特有的与连接状态有关的信息
                     (PDO::ATTR_DRIVER_NAME)//数据库驱动名称
                     (PDO::ATTR_ERRMODE)     //错误提示类型
                     (PDO::ATTR_ORACLE_NULLS) 
                     (PDO::ATTR_PERSISTENT)     //确定连接是否为持久连接,默认值为FLASE
                     (PDO::ATTR_PREFETCH)   //设置应用程序提前获取的数据大小,以K字节为单位
                     (PDO::ATTR_SERVER_INFO)    //包含与数据库特有的服务器信息
                     (PDO::ATTR_SERVER_VERSION)   //包含与数据库服务端版本号有关的信息
                     (PDO::ATTR_TIMEOUT)         //设置超时之前的等待的时间(秒数)

bool setAttribute ( int $attribute , mixed $value )//为一个“数据库连接对象”设定属性 
                  (PDO::ATTR_AUTOCOMMIT, false) //确定PDO是否关闭自动提交功能,设置FALSE值是关闭
                  (PDO::ATTR_CASE,          //强制PDO获取的表字段字符的大小写转换,或原样使用列信息
                                    PDO::CASE_LOWER   //转小写
                                    PDO::CASE_NATURAL//自然,默认
                                    PDO::CASE_UPPER  //转大写
                                    )
                  (PDO::ATTR_ERRMODE,             //设置错误处理的模式
                                    PDO::ERRMODE_SILENT    //仅设置错误号
                                    PDO::ERRMODE_WARNING  //提出 E_WARNING
                                    PDO::ERRMOD_EXCEPTION  //Throw Exception //★OOP
                                    )
                  (PDO::ATTR_ORACLE_NULLS,  //将返回的空字符串转换为SQL的NULL
                                    PDO::NULL_NATURAL      //不转义
                                    PDO::PDO::NULL_EMPTY_STRING //Empty string is converted to NULL
                                    PDO::NULL_TO_STRING       //NULL is converted to an empty string
                                    )
                  (PDO::ATTR_STRINGIFY_FETCHES)
                  (PDO::ATTR_STATEMENT_CLASS)
                  (PDO::ATTR_TIMEOUT)
                  (PDO::MYSQL_ATTR_USE_BUFFERED_QUERY )


string quote (  //为某个SQL中的字符串添加引号
               string $string
               [, int $parameter_type = PDO::PARAM_STR ] 
              )


}

/*------------------------------------------------------------*/
PDOStatement implements Traversable { //预处理类

/* 属性 */
readonlystring $queryString;

/* 方法 */
bool bindColumn (   //用来匹配列名和一个指定的变量名,这样每次获取各行记录时,会自动将相应的列值赋给该变量
                  mixed $column , mixed &$param 
                  [, int $type [, int $maxlen  [, mixed $driverdata ]]] )
                  
bool bindParam (   //将参数绑定到相应的查询占位符上           
                  mixed $parameter ,  mixed &$variable 
                  [, int $data_type = PDO::PARAM_STR  [, int $length [, mixed $driver_options ]]] )
                  
bool bindValue ( //将一个值绑定到对应的一个参数中
                  mixed $parameter , mixed $value [, int $data_type = PDO::PARAM_STR ] )

//bool closeCursor ( void ) //关闭游标,使该声明再次被执行
int  columnCount ( void )  //在结果集中返回列的数目 $stmt->columnCount();

//bool debugDumpParams ( void )
//string errorCode ( void ) // $stmt->errorCode();
//array errorInfo ( void )

bool execute ([ array $input_parameters = array() ] )//【负责执行一个准备好的预处理查询】

mixed fetch ( /* 返回结果集一条记录,并将指针移动到下一个结果集,末尾返回FALSE */   //使用while循环遍历     $stmt->fetch()
               [ int $fetch_style = PDO::FETCH_BOTH        //索引和关联default
                 int $fetch_style = PDO::FETCH_ASSOC      //关联
                 int $fetch_style = PDO::FETCH_NUM      //索引
                 int $fetch_style = PDO::FETCH_OBJ          //对象
                 int $fetch_style = PDO::FETCH_LAZY       //关联、同时返回查询字符串(mixed:obj,arr)
               [, int $cursor_orientation = PDO::FETCH_ORI_NEXT    
               [, int $cursor_offset = 0 ]]] 
               )
               
array fetchAll ( /* 返回所有结果集 */    //使用foreach遍历   $stmt->fetchAll()
               [ int $fetch_style = PDO::FETCH_BOTH       //索引和关联default
                 int $fetch_style = PDO::FETCH_ASSOC       //关联
                 int $fetch_style = PDO::FETCH_NUM     //索引
                 int $fetch_style = PDO::FETCH_OBJ         //对象
                 int $fetch_style = PDO::FETCH_COLUMN    //指定获取那个字段 PDO::FETCH_COLUMN,2
                 
               [, mixed $fetch_argument 
               [, array $ctor_args = array() ]]] 
               )
               
string fetchColumn ([ int $column_number = 0 ] )  //★返回结果集(搜索字段)中下一行某个列的值 $stmt->fetchColumn(2)

//mixed fetchObject ([ string $class_name = "stdClass" [, array $ctor_args ]] )
//mixed getAttribute ( int $attribute )

array getColumnMeta ( int $column ) //★在结果集中返回某一列的属性信息

bool nextRowset ( void )   //检索下一行集(结果集)
int rowCount ( void )  //★返回query()方法执行的SELECT语句受影响的行总数

//bool setAttribute ( int $attribute , mixed $value )
bool setFetchMode ( int $mode )  //★设置需要结果集合的类型

}

/*------------------------------------------------------------*/
PDOException extends RuntimeException {  //异常处理类

/* 属性 */
public array $errorInfo ;
protected string $message ;
protected string $code ;

/* 继承的方法 */
final public string Exception::getMessage ( void )
final public Exception Exception::getPrevious ( void )
final public int Exception::getCode ( void )
final public string Exception::getFile ( void )
final public int Exception::getLine ( void )
final public array Exception::getTrace ( void )
final public string Exception::getTraceAsString ( void )
public string Exception::__toString ( void )
final private void Exception::__clone ( void )
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值