封装的 mysql类, 和sql语句生成类
host = $server['host']; $this->user = $server['user']; $this->pwd = $server['pwd']; $this->port = $server['port']; $this->dbname = $server['dbname']; $this->connect(); }//End of function public static function getInstance($server) { if( self::$isConnect ) { return self::$handle; } self::$handle = new self($server); self::$isConnect = true; return self::$handle; }//End of funtion private function connect() { $this->resource = mysql_connect($this->host.':'.$this->port, $this->user, $this->pwd ) or $this->error("connect fail"); mysql_select_db($this->dbname, $this->resource); return true; } private function getSql($sql) { $operate = array('insert', 'delete', 'update', 'select', 'create'); return $sql; } public function query($sql) { $sql = $this->getSql($sql); mysql_query("SET NAMES UTF8"); $query_result = mysql_query($sql, $this->resource) or $this->error("query fail"); return $query_result; } public function getQueryResult($sql) { $query_result = $this->query($sql); $result = array(); if( !$query_result ) { return $result; } while ( $row = mysql_fetch_assoc($query_result) ) { $result[] = $row; } $result['rows'] = mysql_num_rows($query_result); $query_result = null; return $result; } public function getInsertResult($sql) { $query_result = $this->query($sql); if( !$query_result ) { return false; } return mysql_insert_id($this->resource); } public function getUpdateResult($sql) { $query_result = $this->query($sql); if( !$query_result ) { return false; } return mysql_affected_rows($this->resource); } public function getDeleteResult($sql) { return $this->getUpdateResult($sql); } public function close_connect() { self::$handle = null; self::$isConnect = false; mysql_free_result($this->resource); $this->resource = null; } private function error($msg='') { $msg = "$msg--->>".mysql_error(); die($msg); } }//End of class ?>
로그인 후 복사
2. [文件] DbTool.class.php
primary_key = $primary_key; } } public function getInsertSql($data, $table) { $sql = $key_str = $value_str = ""; foreach($data as $key=>$value) { $key_str .= "{$key}, "; $value_str .= "'{$value}', "; } $key_str = trim($key_str, ', '); $value_str = trim($value_str, ', '); $sql = "INSERT INTO {$table}({$key_str}) VALUES({$value_str})"; $data=null; $key_str=null; $value_str=null; return $sql; } public function getUpdateSql($data, $table) { $pk = $this->primary_key; $id = $data[$pk]; unset($data[$pk]); $sql = $key_value = ""; foreach($data as $key=>$value) { $key_value .= "{$key}='{$value}', "; } $key_value = trim($key_value, ', '); $sql = "UPDATE {$table} SET {$key_value} WHERE $pk='{$id}'"; $data=null; $key_value=null; return $sql; } public function getQuerySql($condition, $table) { $field = empty($condition['field']) ? '*': $condition['field']; $sql = "SELECT {$field} FROM {$table} "; if( isset($condition['where']) ) { $sql .= "WHERE {$condition['where']} "; } if( isset($condition['groupby']) ) { $sql .= "GROUP BY {$condition['groupby']} "; } if( isset($condition['orderby']) ) { $sql .= "ORDER BY {$condition['orderby']} "; } if( isset($condition['limit']) ) { $sql .= "LIMIT {$condition['limit']} "; } $condition=null; return $sql; } public function getDeleteSql($id, $table) { $pk = $this->primary_key; $sql = "DELETE FROM {$table} WHERE $pk='{$id}' "; return $sql; } } ?>
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
스플릿 소설을이기는 데 얼마나 걸립니까?
1 몇 달 전
By DDD
R.E.P.O. 파일 저장 위치 : 어디에 있고 그것을 보호하는 방법은 무엇입니까?
1 몇 달 전
By DDD
R.E.P.O. 최고의 그래픽 설정
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
1 몇 주 전
By DDD

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7393
15


자바 튜토리얼
1630
14


Cakephp 튜토리얼
1358
52


라라벨 튜토리얼
1268
25


PHP 튜토리얼
1217
29

