#1 wo8818
先在服务器ODBC上建立通过数据源,然后框架以类的形式用 odbc_connect()连接数据库后,必须要使用odbc_close()关闭连接吗,比如用下面的代码会不会造成连接数过多?class oracle_ODBC {
public $host = ""; //設置ODBC数据源
public $user = "root"; //帳戶名
public $pwd = "123456"; //密碼
public $table;//数据表名
public $connect_info;//数据库连接信息
public function __construct(){
$this->connect_info=odbc_connect($this->host, $this->user, $this->pwd) or die("站別資料数据连接失败,请找管理员"); //连接数据库
}
public function findAll($conditions = null, $sort = null, $fields = null, $limit = null) //$conditions 只能以字符串形式
{
$where = "";
$fields = empty($fields) ? "*" : $fields;
if(null != $conditions)$where = "WHERE ".$conditions;
if(null != $sort){
$sort = "ORDER BY {$sort}";
}
if(null != $limit and null != $conditions){
$sql = "SELECT {$fields} FROM {$this->table} {$where} AND rownum<={$limit} {$sort}";
}
elseif(null != $limit and null == $conditions){
$sql = "SELECT {$fields} FROM {$this->table} where rownum<={$limit} {$sort}";
}
else{
$sql = "SELECT {$fields} FROM {$this->table} {$where} {$sort}";
}
$result=odbc_exec($this->connect_info,$sql);
$i=0;
while($rows=odbc_fetch_array($result))
{
$getresult[$i]=$rows;
$i=$i+1;
}
return $getresult;
}
}
2016-05-25 09:40:47