会员登录 | 会员注册 | 意见建议 | 网站地图

站长资源综合门户

当前位置:首页 > 站长学院 > 编程程序 > 一个不错的MySQL类

一个不错的MySQL类

时间:2012-04-22 14:07:02   作者:   来源:   点击:

.' as t(id int, pid int, level int, branch text, pos int)';

if($level > 0){

$_sql .= ' where level >='.self::quote($level);

}

if($returnSql) return $_sql;

$_res = self::query(self::SELECT,$_sql,true)->execute($db)->as_array();

if($_res){

return $_res;

}else{

return false;

}

}

public static function begin($db='default'){

DB::query(Database::UPDATE, "BEGIN")->execute($db);

}

public static function commit($db='default'){

DB::query(Database::UPDATE, "COMMIT")->execute($db);

}

public static function rollback($db='default'){

DB::query(Database::UPDATE, "ROLLBACK")->execute($db);

}

/**

* Create a new [Database_Query] of the given type.

*

* // Create a new SELECT query

* $query = DB::query(Database::SELECT, 'SELECT * FROM users');

*

* // Create a new DELETE query

* $query = DB::query(Database::DELETE, 'DELETE FROM users WHERE id = 5');

*

* Specifying the type changes the returned result. When using

* `Database::SELECT`, a [Database_Query_Result] will be returned.

* `Database::INSERT` queries will return the insert id and number of rows.

* For all other queries, the number of affected rows is returned.

*

* @param integer type: Database::SELECT, Database::UPDATE, etc

* @param string SQL statement

* @return Database_Query

*/

public static function query($type, $sql,$as_object = false)

{

return new Database_Query($type, $sql,$as_object);

}

/**

* Create a new [Database_Query_Builder_Select]. Each argument will be

* treated as a column. To generate a `foo AS bar` alias, use an array.

*

* // SELECT id, username

* $query = DB::select('id', 'username');

*

* // SELECT id AS user_id

* $query = DB::select(array('id', 'user_id'));

*

* @param mixed column name or array($column, $alias) or object

* @param ...

* @return Database_Query_Builder_Select

*/

public static function select($columns = NULL)

{

return new Database_Query_Builder_Select(func_get_args());

}

/**

* Create a new [Database_Query_Builder_Select] from an array of columns.

*

* // SELECT id, username

* $query = DB::select_array(array('id', 'username'));

*

* @param array columns to select

* @return Database_Query_Builder_Select

*/

public static function select_array(array $columns = NULL)

{

return new Database_Query_Builder_Select($columns);

}

/**

* Create a new [Database_Query_Builder_Insert].

*

* // INSERT INTO users (id, username)

* $query = DB::insert('users', array('id', 'username'));

*

* @param string table to insert into

* @param array list of column names or array($column, $alias) or object

* @return Database_Query_Builder_Insert

*/

public static function insert($table = NULL, array $columns = NULL)

{

return new Database_Query_Builder_Insert($table, $columns);

}

/**

* Create a new [Database_Query_Builder_Update].

*

* // UPDATE users

* $query = DB::update('users');

*

* @param string table to update

* @return Database_Query_Builder_Update

*/

public static function update($table = NULL)

{

return new Database_Query_Builder_Update($table);

分享到:

网友评论

热门编程程序