Perl & CGI & MySQ Jessica 隨手筆記 2001-10-08 下次再繼續
|
事前準備工作
下載上列這些套件後(請務必切換成root的身份) 請解壓縮 1. tar zxvf 要解壓縮的檔案名稱 2. cd解壓縮後的檔案名稱 3. perl Makefile.PL 4. make test 5. make install 執行上列5步驟就可以安裝好您想裝的modules 了 好啦..全部裝完後,我們的準備工作就完成了,可以開始寫程式囉~~~ |
|
THE DBI CLASS
|
|
|
DBI Class Methods
|
|
| connect | $dbh = DBI->connect("DBI:mysql:$database",$user, $password); |
| available_drivers | @drivers = DBI->available_drivers; |
| data_sources | @sources = DBI->data_sources($driver); |
| trace | DBI->trace($trace_level); |
|
DBI Utility Functions
|
|
| neat | $neat_value = DBI::neat($value, $maxlen); |
| neat_list | $neat_list = DBI::neat_list($listref, $maxlen, $field_sep); |
| dump_results | $rows = DBI::dump_results($sth, $maxlen, $lsep, $fsep, $fh); |
|
DBI Dynamic Attributes
|
|
| $DBI::err | see $dbh->err |
| $DBI::errstr | see $dbh->errstr |
| $DBI::state | see $dbh->state |
| $DBI::rows | ? is this associated with $sth->rows ? |
|
Methods Common to All Handles
|
|
| err | $err_code = $dbh->err; |
| errstr | $err_string = $dbh->errstr; |
| state | $state = $dbh->state; |
| trace | $trace = $dbh->trace; |
| func | $result = $dbh->func(@func_args, $func_name); |
|
Attributes Common to all Handles
|
|
| Warn | $dbh->{Warn} = 1; |
| CompatMode | $dbh->{CompatMode} = 1; |
| InactiveDestroy | $dbh->{InactiveDestroy} = 1; |
| PrintError | $dbh->{PrintError} = 1; |
| RaiseError | $dbh->{RaiseError} = 1; |
| ChopBlanks | $dbh->{ChopBlanks} = 1; |
| LongReadLen | $dbh->{LongReadLen} = 1; |
| LongTruncOk | $dbh->{LongTruncOk} = 1; |
|
Database Handle Methods
|
|
| prepare | $sth = $dbh->prpare($statement); |
| do | $sth->$dbh->do($statement); |
| commit | $dbh->commit; (Not supported by mySQL) |
| rollback | $dbh->rollback; (Not supported by mySQL) |
| disconnect | $dbh->disconnect; |
| ping | $return = $dbh->ping; |
| quote | $sql = $dbh->quote($string); |
|
Statement Handle Methods
|
|
| bind_param | $sth->bind_param($param_num, $bind_value, $bind_type); |
| bind_param_inout | $rv = $sth->bind_param_inout($param_num, \$bind_value,
$max_len); (Not supported by mySQL) |
| execute | $sth->execute; |
| fetchrow_arrayref | $row_array = $sth->fetchrow_arrayref |
| fetchrow_array | @row_array = $sth->fetchrow_array; |
| fetchrow_hashref | $row_hash = $sth->fetchrow_hashref; |
| fetchall_arrayref | $row_all = $sth->fetchall_arrayref; |
| finish | $sth->finish; |
| rows | $rc = $sth->rows; |
| bind_col | $sth->bind_col($column_number, \$bind_var); |
| bind_columns | $sth->bind_columns(\%attr, @bind_var_refs); |
|
Statement Handle Attributes
|
|
| NUM_OF_FIELDS | $num_fields = $sth->{NUM_OF_FIELDS}; |
| NUM_OF_PARAMS | $num_params = $sth->{NUM_OF_PARAMS}; |
| NAME | $names = $sth->{NAME}; |
| NULLABLE | $nullables = $sth->{NULLABLE}; |
| CursorName | $cursor_name = $sth->{CursorName}; (?Not supported by mySQL?) |
|
Debugging
|
|
| DBI_TRACE | DBI_TRACE = 2 perl test_script.pl |
|
THE DBD CLASS
|
|
|
Private MetaData Methods
|
|
| ListDBs | @databases = $dbh->func("$hostname:$port",
'_ListDBs); (see also data_sources) |
| ListTables | @tables = $dbh->func('_ListTables'); |
| ListFields | see NAME |
| ListSelectedFields | see NAME |
|
Database Manipulation
|
|
| CreateDB | $dbh->func($database, '_CreateDB'); |
| DropDB | $dbh->func($database, '_DropDB'); |
|
Private Statement Attributes
|
|
| ChopBlanks | $sth->{ChopBlanks} = 1; |
| insertid | $id = $sth->{insertid}; |
| is_blob | $blobs = $sth->{is_blob}; |
| is_key | $keys = $sth->{is_key}; |
| is_pri_key | $prim_key = $sth->{is_pri_key}; |
| is_num | $num_fields = $sth->{is_num}; |
| is_not_null | $not_nulls = $sth->{is_not_null}; |
| length | $length = $sth->{length}; |
| max_length | $max_lengths = $sth->{max_length}; |
| table | $tables = $sth->{table}; |
| type | $types = $sth->{type}; |