• Adodb for php的Excute使用方法
    时间:2008-11-19   作者:佚名   出处:互联网

    Execute SQL statement $sql and return derived class of ADORecordSet if successful. Note that a record set is always returned on success, even if we are executing an insert or update statement. You can also pass in $sql a statement prepared in Prepare().

    Returns derived class of ADORecordSet. Eg. if connecting via mysql, then ADORecordSet_mysql would be returned. False is returned if there was an error in executing the sql.

    The $inputarr parameter can be used for binding variables to parameters. Below is an Oracle example:

        $conn->Execute("SELECT * FROM TABLE WHERE COND=:val", array('val'=> $val));

    Another example, using ODBC,which uses the ? convention:

        $conn->Execute("SELECT * FROM TABLE WHERE COND=?", array($val));

      Binding variables

    Variable binding speeds the compilation and caching of SQL statements, leading to higher performance. Currently Oracle, Interbase and ODBC supports variable binding. Interbase/ODBC style ? binding is emulated in databases that do not support binding. Note that you do not have to quote strings if you use binding.

    Variable binding in the odbc, interbase and oci8po drivers.

    $rs = $db->Execute('select * from table where val=?', array('10'));
    

    Variable binding in the oci8 driver:

    $rs = $db->Execute('select name from table where val=:key', 
      array('key' => 10));
    

     

    Bulk binding

    Since ADOdb 3.80, we support bulk binding in Execute(), in which you pass in a 2-dimensional array to be bound to an INSERT/UPDATE or DELETE statement.

    $arr = array(
    	array('Ahmad',32),
    	array('Zulkifli', 24),
    	array('Rosnah', 21)
    	);
    $ok = $db->Execute('insert into table (name,age) values (?,?)',$arr);
    

    This provides very high performance as the SQL statement is prepared first. The prepared statement is executed repeatedly for each array row until all rows are completed, or until the first error. Very useful for importing data.

    网友留言/评论

    我要留言/评论