-
- /****------------------*******
- * Copyright (C) 2007 by 耿鸿飞 *
- * ghf@localhost.localdomain *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * @link http://bbs.it-home.org
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ****------------------*******/
- define("DB_HOST","localhost");
- define("DB_USER","root");
- define("DB_PASS","");
- define("DB_NAME","test"):
-
- class DBConnect()
- {
- private static $DB;
-
- private function & getCon()
- {
- if(self::DB == nuyll)
- {
- self::DB = &mysql_connect(DB_HOST,DB_USER,DB_PASS) or die("连接数据库失败!");
- mysql_select_db(self::DB,DB_NAME);
- }
- return self::DB;
- }
- /*************
- * insert or update data to database;
- *
- */
- public upDate($sql)
- {
- return mysql_query($sql,this.getCon());
- }
- /***************
- * query data from database and return data that type is array
- */
- public query($sql)
- {
- $rs = mysql_query($sql,this.getCon());
- $rows = array();
- $i = 0;
- while($row = mysql_fetch_array($rs))
- {
- rows[$i] = $row;
- $i++;
- }
- mysql_free_result($rs);
- return $rows;
- }
- /************
- * query database and return data rows;
- */
- public query_num_rows($sql)
- {
- $rs = mysql_query($sql,this.getCon());
- return mysql_num_row($rs);
- }
- /**********
- * close dbconnection;
- */
- public colse()
- {
- mysql_colse(this.getCon());
- self::DB = null;
- }
- }
- ?>
复制代码
|