標籤雲

搜尋此網誌

2008/03/09

php-物件導向 mysqli

連線:
class mysqli {
__construct ( [string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket]]]]]] )}
//Open a new connection to the MySQL server

int mysqli_connect_errno ( void )
//Returns the last error code number from the last call to mysqli_connect()

string mysqli_connect_error ( void )
//Returns the last error message string from the last call to mysqli_connect().

檢索:
class mysqli {
mixed query ( string $query [, int $resultmode] )
}
//Returns TRUE on success or FALSE on failure. For SELECT, SHOW, DESCRIBE or EXPLAIN mysqli_query() will return a result object.

class mysqli_result {
array fetch_assoc ( void )
}
//以關聯式陣列形式傳回, 因此重複的列名只有最後一筆會包含, 當無下一筆時傳回 NULL

class mysqli_result {
mixed fetch_array ( [int $resulttype] )
}
//傳回以數字為索引的陣列(不用擔心列名重複), 當無下一筆時傳回 NULL

轉義以過濾輸入值(防止 injection attack):
class mysqli {
string escape_string ( string $escapestr )
string real_escape_string ( string $escapestr )
}
//過濾傳入的字串, 轉義以下特殊符號 NUL (ASCII 0), \n, \r, \, ', ", Control-Z

交易處理(transaction):
class mysqli {
bool autocommit ( bool $mode ) //開啟或關閉自動提交, 建議關閉
bool commit ( void )
bool rollback ( void )
}

預備敘述( Prepared Statements ):
class mysqli {
mysqli_stmt prepare ( string $query )
}
//產生 mysqli_stmt 物件, $query 中欄位參數的值應以 ? 取代

class mysqli_stmt {
bool bind_param ( string $types, mixed &$var1 [, mixed &$...] )
//綁定參數, 將值與參數名稱指定給 mysqli_stmt 物件

bool bind_result ( mixed &$var1 [, mixed &$...] )
//綁定結果(將結果綁定到 php 變數上)

bool fetch ( void )
//將綁定結果依序放入敘述中, 成功傳回 True, 失敗傳回 False, 沒有值時傳回 Null
}

沒有留言: