SqlUtil.object
上传用户:xiao730204
上传日期:2007-01-04
资源大小:141k
文件大小:3k
- <?php
- class SqlUtil extends BaseObject {
- Function SqlUtil() {
- $this->BaseObject( 'SqlUtil' );
- }
- Function Quote( $value ) {
- return '"' . $value . '"';
- }
- Function DeleteStatement( $table, $match_criteria = '' ) {
- $delete_statement = '';
- $delete_statement = 'DELETE FROM ' . $table;
- if ( $match_criteria != '' ) {
- $delete_statement .= ' WHERE ' . $match_criteria;
- }
- return $delete_statement;
- }
- Function UpdateStatement( $table, $table_elems, $match_criteria = '' ) {
- $update_statement = '';
- $update_statement .= 'UPDATE ' . $table . ' SET ';
- $more_than_one = 0;
- reset( $table_elems );
- while( list( $field_name, $field_value ) = each( $table_elems ) ) {
- if ( $more_than_one != 0 ) {
- $update_statement .= ', ';
- }
- $update_statement .= $field_name . ' = ' . $this->Quote( $field_value );
- $more_than_one++;
- }
- if ( $match_criteria != '' ) {
- $update_statement .= ' WHERE ';
- $update_statement .= $match_criteria;
- }
- return $update_statement;
- }
- Function InsertStatement( $table, $table_elems ) {
- $insert_statement = '';
- $insert_statement .= 'INSERT INTO ' . $table . ' ';
- $insert_statement .= '( ';
- $more_than_one = 0;
- reset( $table_elems );
- while( list( $field_name, $field_value ) = each( $table_elems ) ) {
- if ( $more_than_one != 0 ) {
- $insert_statement .= ', ';
- }
- $insert_statement .= $field_name;
- $more_than_one++;
- }
- $insert_statement .= ' ) VALUES ( ';
- $more_than_one = 0;
- reset( $table_elems );
- while( list( $field_name, $field_value ) = each( $table_elems ) ) {
- if ( $more_than_one != 0 ) {
- $insert_statement .= ', ';
- }
- $insert_statement .= $this->Quote( $field_value );
- $more_than_one++;
- }
- $insert_statement .= ' )';
- return $insert_statement;
- }
- Function SelectStatement( $tables, $table_elems, $match_criteria = '' ) {
- $select_statement = '';
- $select_statement = 'SELECT ';
- $more_than_one = 0;
- for( $i = 0; $i < count( $table_elems ); $i++ ) {
- $field_name = $table_elems[ $i ] ;
- if ( $more_than_one != 0 ) {
- $select_statement .= ', ';
- }
- $select_statement .= $field_name;
- $more_than_one++;
- }
- $select_statement .= ' FROM ';
- $more_than_one = 0;
- reset( $tables );
- for( $i = 0; $i < count( $tables ); $i++ ) {
- $table_name = $tables[ $i ] ;
- if ( $more_than_one != 0 ) {
- $select_statement .= ', ';
- }
- $select_statement .= $table_name;
- }
- if ( $match_criteria != '' ) {
- $select_statement .= ' WHERE ' . $match_criteria;
- }
- return $select_statement;
- }
- }
- ?>