澳门新葡8455最新网站mssql+php数据库操作类

OCI_NUM)) {$result[] = $data[0] . ‘=’ . $data[1];}$result =
implode(‘|’, $result);$this-close($dataSet);break;

 /**
  * 获取全部数据
  *
  * @param string $sql
  * @return array 二维数组
  */
 function fetchAll($sql)
 {
  $result = $this->query($sql);
  while($row = $result->fetch_array($this->_fetch_method))
  {
   $data[] = $row;
  }
  return $data;
 }

default: //dataset 数据集,当返回数据格式为数据集时,select

    /**
     * Enter description here…
     *
     */
 function __desstruct()
 {
  $this->close();
 }

$sql . ‘/font/b]出错!br font

 /**
  * Enter description here…
  *
  * @param string $type
  * @return unknown
  */
 function getInfo($type=’server’)
 {
  switch($type){
   case ‘server’:
    $result = $this->server_info;
    break;
   case ‘client’:
    $result = $this->client_info;
    break;
   default:
    $result = $this->server_info;
    break;
  }
  return $result;
 }
}

($dataSet ,0 );$idx = $firstColumnInfo-name;//column
name}$this-close($dataSet);//print_r($result);return ($fieldCount=1) ?
$result[$idx] : $result;} else {return false ;}}/** * 取ID自递增值
* * @return int * @access public */public function getInsertId()
{return $this-getValue(‘select @@identity’);}/** * 取序列 * @param
$seq 序列名 * @return int * @access public */public function
getSeq($seq = ”) { $this-execute(‘BEGIN TRANSACTION adodbseq’);$ok =
$this-execute(update $seq with (tablock,holdlock)

 function fetchFree()
 {
  return $this->free_result();
 }

if ($result = $this-fetchRecord($dataSet,$dataFormat)) {$fieldCount =
$this-getFieldCount($dataSet);$idx = 0;if($dataFormat ==
MSSQL_ASSOC){//如果使用

 /**
  * 更新
  *
  * @param string $table
  * @param array $fields
  * @param string $where
  * @return null
  * @deprecated 键名为插入的字段值 键值为插入的值
  */
 function update($table,$fields,$where)
 {
  if(empty($table)){return false;}
  if(empty($fields)){return false;}
  if(empty($where)){return false;}
  foreach($fields as $key=>$v)
  {
   $condition[] = “{$key}='”.$this->quoteInto($v).”‘”;
  }
  $sql = “UPDATE “.$table.”
    SET “.implode(‘,’,$condition).” WHERE “.$where;
  $this->query($sql);
 }

$fieldValue . ‘)’;//return $sql;return $this-execute($sql);}/** *
更新一条记录 * @param string $tableName 表名 * @param array
$fieldArray 字段数组 * @param string $whereForUpdate 查询条件 * @param
string $whereForUnique 唯一性条件 * @return int * @access public
*/public function update($tableName, $fieldArray,

 /**
  * 设置返回值类型
  *
  * @param int $type
  */
 function setFetchMethod($type=2)
 {
  switch($type)
  {
澳门新葡8455最新网站,   case ‘1’:
    $this->_fetch_method = MYSQLI_NUM;
    break;
   case ‘2’:
    $this->_fetch_method = MYSQLI_ASSOC;
    break;
   case ‘3’:
    $this->_fetch_method = MYSQLI_BOTH;
    break;
   default:
    $this->_fetch_method = MYSQLI_ASSOC;
    break;
  }
 }

的值不合法!’);}if ($whereForUnique) {$where = ‘ WHERE ‘ .
$whereForUnique;$isExisted = $this-getValue(‘SELECT COUNT(*) FROM ‘

 /**
  * 插入前转义
  *
  * @param string|array $str
  * @return string
  */
 function quoteInto($str)
 {
  if(is_array($str)){
   foreach ($str as $key=>$val){
    $str[$key] = $this->real_escape_string($val);
   }
  }else{
   $str = $this->real_escape_string($str);
  }
  return $str;
 }

. $tableName . $where);if ($isExisted) {throw new
DbException(‘记录已经存在!’,

mysql教程i 数据连接类
class Mydb extends mysqli
{
    protected $_databasehost = ‘localhost’;
    protected $_databaseuser = ‘root’;
    protected $_databasepass = ‘123456’;
    protected $_databasename = ‘test’;
    protected $_databaseport = ‘3306’;
 protected $_fetch_method = MYSQLI_ASSOC;
 protected $_databasechar = ‘utf8’;
   
 /**
  * Enter description here…
  *
  * @param string $host
  * @param string $user
  * @param string $pass
  * @param string $name
  * @param int $port
  * @param string $char
  */
    function
__construct($host=”,$user=”,$pass=”,$name=”,$port=”,$char=”)
    {   
        $this->_databasehost = empty($host) ?
$this->_databasehost : $host;
        $this->_databaseuser = empty($user) ?
$this->_databaseuser : $user;
        $this->_databasepass = empty($pass) ?
$this->_databasepass : $pass;
        $this->_databasename = empty($name) ?
$this->_databasename : $name;
        $this->_databaseport = empty($port) ?
$this->_databaseport : $port;
  $this->_databasechar = empty($char) ? $this->_databasechar :
$char;
        try{
           
parent::__construct($this->_databasehost,$this->_databaseuser,
                $this->_databasepass,$this->_databasename,
                $this->_databaseport);
            if(mysqli_connect_errno()){
                die(“服务器连接失败”);
            }
            if(!parent::set_charset($this->_databasechar)){
                die(“数据库教程无法使用utf-8编码”);
            }           
        }catch(Exception $e){
            die($e->getMessage());
        }   
    }
   

DbException::DB_RECORD_IS_EXISTED);}}$fieldNameValueList =
array();foreach ($fieldArray as $fieldName = $fieldValue) {if
(!is_int($fieldName)) {$fieldNameValueList[] = $fieldName . ‘=” .

 /**
  * 插入
  *
  * @param string $table
  * @param array $fields
  * @return int
  * @deprecated 键名为插入的字段值 键值为插入的值
  */
 function insert($table,$fields)
 {
  if(empty($table)){return false;}
  if(empty($fields)){return false;}
  $insertFields = @implode(‘,’,@array_keys($fields));
  $arrayValues = @array_values($fields);
  $result = $this->quoteInto($arrayValues);
  $insertValues =
“‘”[email protected](“‘,'”,$result).”‘”;
  $sql = “INSERT INTO “.$table.”(“.$insertFields.”)
    VALUES(“.$insertValues.”)”;
  $this->query($sql);
  return $this->insert_id;
 }
 

case ‘arrayassoc’: //数组,有BUG,这里面需要用列名为索引!当只

 /**
  * Enter description here…
  *
  * @param string $type
  * @return unknown
  */
 function getVersion($type=’server’)
 {
  switch($type){
   case ‘server’:
    $result = $this->server_version;
    break;
   case ‘client’:
    $result = $this->client_version;
    break;
   default:
    $result = $this->server_version;
    break;
  }
  return $result;
 }

$whereForUpdate=NULL, $whereForUnique=NULL) {if (!$tableName ||
!$fieldArray || !is_array($fieldArray)) {throw new Exception(‘参数
$tableName 或 $fieldArray

 function selectDb($name)
 {
   $this->_databasename = empty($name) ? $this->_databasename :
$name;
   return $this->select_db($this->_databasename);
 }

”’;}}$fieldName = implode(‘,’, $fieldNameList);$fieldValue =
implode(‘,’, $fieldValueList);$sql = ‘INSERT INTO ‘ . $tableName . ‘(‘.
$fieldName . ‘) VALUES (‘ .

数据连接类 class Mydb extends mysqli {
protected $_databasehost = ‘localhost’; protected $_databaseuser =
‘root’; protected $_databasepass = ‘123456’; protected $…

1);$i = 0;while ($data = $this-fetchRecord($dataSet)) {$result[$i] =
($isMultiField) ? $data :

 /**
  * 获取一条数据
  *
  * @param string $sql
  * @return array 一维数组
  */
 function fetchRow($sql)
 {
  $result = $this->query($sql);
  $row = $result->fetch_array($this->_fetch_method);
  return $row;
 }

有array,hashmap,hashmap_str,dataset * @param int $rowFrom
启始行号,行号从1开始 * @param int $rowTo 结束行号,值为0表示 *
@result array * @access public */public function select($sql,
$dataFormat = ‘array’, $rowFrom = 0,

/** * 查询的SQL语句 * @var string $sql */public $sql= ” ;public
$transCnt = 0;/** * 执行查询的模式,值为 OCI_COMMIT_ON_SUCCESS 或
OCI_DEFAULT * @var string $excuteMode */public $executeMode=
OCI_COMMIT_ON_SUCCESS ;

self::MAX_ROW_NUM, $error = true) {//echo $this-ds-name;if ($rowTo !=
self::MAX_ROW_NUM) {$nrows = $rowTo – $rowFrom + 1; }$offset =
$rowFrom;if ($nrows 0) {$nn = $nrows + $offset – 1;$sql =
preg_replace(‘/(^s*selects+

DbException::DB_OPEN_FAILED);}*/$id = @mssql_query(select @@ERROR,
$this-ds-connect);if (!$id) {return false;}$arr =
mssql_fetch_array($id);@mssql_free_result($id);if (is_array($arr))
{$result[‘code’] = $arr[0]; } else {return $result[‘code’] =
-1;}return $result;}/** * 错误信息处理 * @param string $errorId
错误ID * @param string $errorMessage 错误信息 * @access protected
*/protected function error($errorId, $errorMessage) {throw new
DbException($errorMessage, $errorId);}/** * 执行SQL语句 * @param
string $sql SQL语句 * @return object * @param int $rowFrom
启始行号,行号从1开始 * @param int $rowTo 结束行号,值为0表示 *
@access public * @see DbQuery::open */public function execute($sql =
”, $rowFrom = 0, $rowTo =

. $tableName . $where);if ($isExisted) {throw new
DbException(‘记录已经存在!’,

MSSQL_ASSOC,且只有一列时,则需要知道第一列的列名.$firstColumnInfo =
mssql_fetch_field

$whereForUpdate;return $this-execute($sql);//return $sql;}/** *
选择一条记录 * @param string $sql sql语句 * @param string $dataFormat
返回数据格式, 值

self::MAX_ROW_NUM) {$this-dataSet = $this-execute($sql, $rowFrom,
$rowTo);$this-sql = $sql ;return $this-dataSet;}

MSSQL_ASSOC,且只有一列时,则需要知道第一列的列名.$firstColumnInfo =
mssql_fetch_field

color=#FF0000 [‘. $sqlError[‘code’] . ‘]: ‘. $sqlError[‘message’]
. ‘/font’ ;$this-error(DbException::DB_QUERY_ERROR,

$data[0];$i++;}$this-close($dataSet);break;

有一列有时候$result = array();$isMultiField =
($this-getFieldCount($dataSet)

. $tableName . $where);}}

的值不合法!’);}if ($whereForUnique) {$where = ‘ WHERE ‘ .
$whereForUnique;$isExisted = $this-getValue(‘SELECT COUNT(*) FROM ‘

$fieldValue . ”’;}}$fieldNameValue = implode(‘,’,
$fieldNameValueList);if ($whereForUpdate) {$whereForUpdate = ‘ WHERE ‘ .
$whereForUpdate;}$sql = ‘UPDATE ‘ . $tableName . ‘ SET ‘ .
$fieldNameValue .

相关文章

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图