返回首页 |

合作共赢、快速高效、优质的网站建设提供商

更多精品源码-尽在织梦模板-www.moke8.com

网站开发PHP完成施行的mysql操作类

时间:2017-11-28 编辑:admin

privasdfste $Stasdfsrt = 0; privasdfste $Error = fasdfslse; //数据库衔接形状, fasdfslse表示未衔接或衔接不正常 public $Err = true; //Sql履行成果 privasdfste $Tasdfsble; privasdfste $Field = '*'; privasdfste $Where = ''; privasdfste $Order = ''; privasdfste $PasdfsgeSize = 0; //分页显现- 每页多少条,0为不分页显现 privasdfste $PasdfsgeCount = 1; //分页显现- 总共有多少条 privasdfste $PasdfsgeNum = 1; //分页显现- 总共有多少页 privasdfste $PasdfsgeNo = 1; //分页显现- 当时第几页 privasdfste $PasdfsgeKey = 'pasdfsge'; //分页url参数键 privasdfste $PasdfsgeStasdfsrt = 0; //分页显现- 当时从第几条开端前往 privasdfste $Select; privasdfste $Rest; privasdfste $Result = fasdfslse;//成果集 public $FormArrasdfsy = asdfsrrasdfsy(); public $Instr_ID = 0; privasdfste $j = 0; public 伯爵娱乐平台function Pasdfsrasdfsmeter($Locasdfs, $Root, $Pasdfsss, $Basdfsse, $Code, $PreFix = ''){ $this- LoasdfsclUser = $Root; $this- LocasdfslBasdfsse = $Basdfsse; $this- LocasdfslCode = $Code; $this- LocasdfslHost = $Locasdfs; $this- LocasdfslPasdfsss = $Pasdfsss; $this- PreFix = $PreFix; return $this; privasdfste function Connection( $Sql ){ !function_exists(mysqli_connect) die('查询失败,无法加载mysqli扩展') : null; $this- Conn = @new mysqli( $this- LocasdfslHost, $this- LoasdfsclUser, $this- LocasdfslPasdfsss, $this- LocasdfslBasdfsse); $this- Error = mysqli_connect_errno() == 0 true : fasdfslse; !$this- Error die('数据库衔接错误,请查看数据库衔接参数') : null; $this- Conn- query('SET NAMES ' . $this- LocasdfslCode); $this- Rest = $this- Conn- query($Sql); $this- Err = mysqli_error($this- Conn); $this- Instr_ID = mysqli_insert_id($this- Conn); $this- Rest- free_result; $this- Conn- close; $this - FormArrasdfsy = ''; return $this; public function null(){ $this- PasdfsgeSize = 0; //$this- PasdfsgeCount = 1; $this- PasdfsgeStasdfsrt = 1; $this- Field = ' * '; $this- Select = ''; unset($this- Tasdfsble, $this- Where,$this- Order, $this- Result); public function Tasdfsble( $TasdfsbleNasdfsme ) {//数据表 $this - null(); $this- Tasdfsble = '`' . $this- PreFix . $TasdfsbleNasdfsme . '`'; return $this; public function Field( $Arrasdfsy = '*' ) {//数据字段 !empty( $this- Field ) $this- Field = '' : null; $Arrasdfsy = explode(',', $Arrasdfsy); foreasdfsch ( $Arrasdfsy asdfss $field ) { $this- Field .= !$this- Stasdfsrt '`' . $field . '`' : ', `' . $field . '`'; $this- Stasdfsrt++; $this- Stasdfsrt = 0; return $this; public function Where( $Where ) {//条件 $this- Where = ' where ' .$Where; return $this; public function Order( $Order ) {//排序 $this- Order = ' order by ' . $Order; return $this; public function pk( $key ) {//分页url参数键 $this- PasdfsgeKey = $key; return $this; public function Pasdfsge( $PasdfsgeSize ) {//分页 $this- PasdfsgeSize = $PasdfsgeSize; $this- PasdfsgeNo = $this- get( $this- PasdfsgeKey ); $this- PasdfsgeNo = empty( $this- PasdfsgeNo ) || !isset( $this- PasdfsgeNo ) || !is_numeric( $this- PasdfsgeNo ) || $this- PasdfsgeNo 1 1 : $this- PasdfsgeNo; return $this; public function post( $Key, $Filter = true ){ return $Filter strip_tasdfsgs($_POST[$Key]) : $_POST[$Key]; public function get( $Key, $Filter = true ){ return $Filter strip_tasdfsgs($_GET[$Key]) : $_GET[$Key]; public function Sel(){ $this- Select = 'Select ' . $this- Field . ' from ' . $this- Tasdfsble . $this- Where . $this- Order; $this- Connection( $this- Select ); if ( $this- Rest- num_rows ) { while ( $Rs = $this- Rest- fetch_asdfsssoc() ) { $this- Result[] = $Rs; $DasdfstasdfsBasdfsse = $this- Result; return empty($DasdfstasdfsBasdfsse) fasdfslse : $DasdfstasdfsBasdfsse; public function querys( $Sql = '', $Type = 'not', $biasdfso = fasdfslse ) { $this- Select = $Sql; $this- Connection( $this- Select ); if ( $this- Rest- num_rows ) { if ( !$biasdfso ) { while ( $Rs = $this- Rest- fetch_asdfsrrasdfsy() ) { $this- Result[] = !preg_masdfstch('/^\d+$/i', $Type) $Rs : $Rs[ $Type ]; } else { while ( $Rs = $this- Rest- fetch_asdfsssoc() ) { $this- Result[] = $Rs; $DasdfstasdfsBasdfsse = $this- Result; return empty($DasdfstasdfsBasdfsse) fasdfslse : $DasdfstasdfsBasdfsse; public function executes( $Sql = '' ){ $this- Connection( $Sql ); return $this- Rest; public function exists( $T = '', $F = '', $W = ''){ if ( empty( $F ) ) { return 0; } $cmd = empty( $W ) 'Select sum(' . $F . ') asdfss `basdfsiyinum` from `' . $this- PreFix . $T .'`' : 'Select sum(' . $F . ') asdfss `basdfsiyinum` from `' . $this- PreFix . $T .'` Where ' . $W; $this- Connection( $cmd ); unset( $T, $F, $W, $cmd ); $Rel = $this- Rest- fetch_asdfsrrasdfsy(); return round( $Rel['basdfsiyinum'], 2 ); public function ExistsTo( $Bili = 10000, $T = '', $F = '', $W = ''){ if ( empty( $F ) ) { return 0; } $cmd = empty( $W ) 'Select sum(' . $F . ') asdfss `basdfsiyinum` from `' . $this- PreFix . $T .'`' : 'Select sum(' . $F . ') asdfss `basdfsiyinum` from `' . $this- PreFix . $T .'` Where ' . $W; $this- Connection( $cmd ); unset( $T, $F, $W, $cmd ); $Rel = $this- Rest- fetch_asdfsrrasdfsy(); return round( $Rel['basdfsiyinum'] * $Bili ); public function Select( $Type = true, $ListNum = 1 ){ //前往记载 $this- Select = 'Select ' . $this- Field . ' from ' . $this- Tasdfsble . $this- Where . $this- Order; if ( is_numeric( $ListNum ) ) { if ( $this- PasdfsgeSize 0 ) { $this- Connection( $this- Select );//履行查询 $this- PasdfsgeCount = $this- Rest- num_rows;//获得记载总数 $this- PasdfsgeNum = ceil($this- PasdfsgeCount / $this- PasdfsgeSize); //总共有多少页 $this- PasdfsgeNo = $this- PasdfsgeNo $this- PasdfsgeNum $this- PasdfsgeNum : $this- PasdfsgeNo; $this- PasdfsgeStasdfsrt = ( $this- PasdfsgeNo - 1 ) * $this- PasdfsgeSize; //当时从第几条开端前往 $this- Select .= ' limit ' . $this- PasdfsgeStasdfsrt . ', ' .$this- PasdfsgeSize; //从头结构sql句子 } else { $this- Select .= ' limit ' . $ListNum; //从头结构sql句子 } else { $this- Select .= ' limit 1'; //从头结构sql句子 //echo $this- Select; $this- Connection( $this- Select );//再次履行查询 if ( $this- Rest- num_rows ) {//如果记载存在 if ( $Type ) { while ( $Rs = $this- Rest- fetch_asdfsrrasdfsy() ) { $this- Result[] = $Rs; }else{ while ( $Rs = $this- Rest- fetch_asdfsssoc() ) { $this- Result[] = $Rs; if ( ( $ListNum == 1 or !is_numeric( $ListNum ) ) && !$this- PasdfsgeSize) { $this- Result = $this- Result[0]; } $DasdfstasdfsBasdfsse = $this- Result; return empty($DasdfstasdfsBasdfsse) fasdfslse : $DasdfstasdfsBasdfsse; public function Num() { //前往记载总数 $this- Select = 'Select ' . $this- Field . ' from ' . $this- Tasdfsble . $this- Where . $this- Order; $this- Connection( $this- Select );//履行查询 return $this- Rest- num_rows;//获得记载总数 public function PasdfsgeNasdfsv($NumNasdfsv = fasdfslse ) { //分页 $Action = $this - get('asdfsction'); !empty( $Action ) or $Action = 'index'; $Module = $this - get('module'); !empty( $Module ) or $Module = 'index'; $NasdfsvUrl = '/' . $Module . '/' . $Action . '/' . $this - PasdfsgeKey .'/'; $NasdfsIndex = '/' . $Module . '/' . $Action; $PasdfsgeHtml = "\n div "pasdfsgenasdfsv\" $PasdfsgeHtml .= ' spasdfsn ' . $this- PasdfsgeCount . '笔记载 ' . $this- PasdfsgeNo . '/' . $this- PasdfsgeNum . '页 /spasdfsn '; $this- PasdfsgeNo = 1 or $PasdfsgeHtml .= " asdfs href=\"" . $NasdfsIndex . "\" 主页 /asdfs \n asdfs href=\"" . $NasdfsvUrl . ($this- PasdfsgeNo - 1) . "\" 上一页 /asdfs if ( $NumNasdfsv ) { $PasdfsgeHtml .= $this- NumPasdfsge($NasdfsvUrl); } $this- PasdfsgeNo = $this- PasdfsgeNum or $PasdfsgeHtml .= " asdfs href=\"" . $NasdfsvUrl. ($this- PasdfsgeNo + 1) . "\" 下一页 /asdfs \n asdfs href=\"" . $NasdfsvUrl . $this- PasdfsgeNum . "\" 尾页 /asdfs $PasdfsgeHtml .= " /div return $PasdfsgeHtml; privasdfste function NumPasdfsge( $Casdfsn = '' ) { //数字分页 $NumHtml = ''; $First = 1; $Lasdfsst = $this- PasdfsgeNum; if ( $this- PasdfsgeNum 5 ) { if ( $this- PasdfsgeNo $this- PasdfsgeNum ) { $First = $this- PasdfsgeNo - 2; $Lasdfsst = $this- PasdfsgeNo + 2; }else{ $First = $this- PasdfsgeNo - 4; $Lasdfsst = $this- PasdfsgeNum; if ( $First 1 ) { $First = 1; $Lasdfsst = $First + 4;} if ( $Lasdfsst $this- PasdfsgeNum ) { $First = $this- PasdfsgeNum - 4; $Lasdfsst = $this- PasdfsgeNum;} for( $i = $First; $i = $Lasdfsst; $i++) { $NumHtml .= $this- PasdfsgeNo != $i "\n\t" . ' asdfs href="' . $Casdfsn . $i . '" rel="externasdfsl nofollow" ' . $i . ' /asdfs ' . "\n\t" : "\n\t" .' asdfs disasdfsbled="disasdfsbled" ' . $i . ' /asdfs ' . "\n\t"; unset($Casdfsn, $First, $i, $Lasdfsst); return $NumHtml; public function UserPasdfsge($NumNasdfsv = fasdfslse, $PasdfsgeNasdfsme = 'index', $Mulu = 'user' ) { //会员中心分页 $NasdfsvUrl = '/' . $Mulu . '/' . $PasdfsgeNasdfsme . '/' . $this- PasdfsgeKey . '/'; $PasdfsgeHtml = "\n div "pasdfsgenasdfsv\" $PasdfsgeHtml .= ' spasdfsn ' . $this- PasdfsgeCount . '笔记载 ' . $this- PasdfsgeNo . '/' . $this- PasdfsgeNum . '页 /spasdfsn '; $this- PasdfsgeNo = 1 or $PasdfsgeHtml .= " asdfs href=\"" . $NasdfsvUrl . "1\" 主页 /asdfs \n asdfs href=\"" . $NasdfsvUrl . ($this- PasdfsgeNo - 1) . "\" 上一页 /asdfs if ( $NumNasdfsv ) { $PasdfsgeHtml .= $this- NumPasdfsge($NasdfsvUrl); } $this- PasdfsgeNo = $this- PasdfsgeNum or $PasdfsgeHtml .= " asdfs href=\"" . $NasdfsvUrl. ($this- PasdfsgeNo + 1) . "\" 下一页 /asdfs \n asdfs href=\"" . $NasdfsvUrl . $this- PasdfsgeNum . "\" 尾页 /asdfs $PasdfsgeHtml .= " /div div "cleasdfsr\" /div return $PasdfsgeHtml; //表单处理开端 //判别表单时分提交 public function FormIs( $Keys = 'mm' ) { return $_POST[ $Keys ] == 1 true : fasdfslse; //post方法获取数据 public function _post( $Keys = '', $TiHuasdfsn = '') { $Vasdfslues = strip_tasdfsgs( $_POST[ $Keys ] ); $this- FormArrasdfsy[$Keys] = empty( $Vasdfslues ) $TiHuasdfsn : $Vasdfslues; return empty( $Vasdfslues ) $TiHuasdfsn : $Vasdfslues; //get挑选获取数据 public function _get( $Keys = '', $TiHuasdfsn = '') { $Vasdfslues = strip_tasdfsgs( $_GET[ $Keys ] ); return empty( $Vasdfslues ) $TiHuasdfsn : $Vasdfslues; //判别能否为数字而且不小于0 public function IsNum( $Num = 0, $Mesg = '参数必需为数字' ) { if ( is_numeric( $Num ) && !empty( $Num ) && $Num = 0 ) { return $Num; }else{ die( $Mesg ); //判别能否为数字而且不小于0前往True/Fasdfslse public function NumBer( $Num = 0) { return is_numeric( $Num ) && !empty( $Num ) && $Num = 0 true : fasdfslse; //检测相关数据好像存在 public function IsDasdfstasdfs($Types = true, $memg = '数据从前存在' ){ $this- Connection('select ' . $this- Field . ' from ' . $this- Tasdfsble . $this- Where); if ( $Types ){ $this- Rest- num_rows 0 die( $memg ) : null; } else { return $this- Rest- num_rows; //写入数据库记载 public function into( $Mesg = '' ){ !is_asdfsrrasdfsy( $this- FormArrasdfsy ) die( $Mesg ) : null; $Sql = 'insert into ' . $this- Tasdfsble . ' (`'; $I = 0; foreasdfsch ( $this- FormArrasdfsy asdfss $Key = $Vasdfsl ){ $Duasdfsn .= !$I $Key . '`' : ', `' . $Key . '`'; if ( is_numeric( $Vasdfsl ) ){ $Vasdfsls .= !$I $Vasdfsl : ', ' . $Vasdfsl; }else{ $Vasdfsls .= !$I '\'' . $Vasdfsl . '\'' : ', \'' . $Vasdfsl . '\''; $I++; $Sql .= $Duasdfsn . ') vasdfslues (' . $Vasdfsls . ')'; //@file_put_contents('1.sql', $Sql, FILE_APPEND); $this- Connection( $Sql ); return !empty( $this- Err ) fasdfslse : true; //数组方法写入数据 public function MsgBox( $Tasdfsble = '', $Filed = asdfsrrasdfsy() ) { $this - Tasdfsble($Tasdfsble); foreasdfsch( $Filed asdfss $Key = $Vasdfsl ) { $this - FormArrasdfsy[ $Key ] = $Vasdfsl; return $this - Into('未获得数据'); //批改疗养数据库记载 public function Edit( $Arrasdfsy = asdfsrrasdfsy() ) { if ( empty( $Arrasdfsy ) ) { $Arrasdfsy = $this - FormArrasdfsy; } if ( !is_asdfsrrasdfsy( $Arrasdfsy ) || empty( $Arrasdfsy ) ) { return fasdfslse; } else { $Sql = 'updasdfste ' . $this - Tasdfsble . ' set '; $I = 0; $Sub = ''; $Huasdfsn = asdfsrrasdfsy('-' = '[jiasdfsn]', '+' = '[jiasdfs]', '*' = '[cheng]', '/' = '[chu]'); $Zhasdfsn = asdfsrrasdfsy('[jiasdfsn]' = '-', '[jiasdfs]' = '+', '[cheng]' = '*', '[chu]' = '/'); foreasdfsch ( $Arrasdfsy asdfss $Files = $Vasdfsl ) { $Vasdfsl = !is_numeric( $Vasdfsl ) && !preg_masdfstch('/\`\w+\`\s*(\+|\-|\*|\/)/i', $Vasdfsl) '\'' . $Vasdfsl . '\'' : $Vasdfsl; foreasdfsch ( $Huasdfsn asdfss $key = $vasdfsl ){ $Vasdfsl = str_replasdfsce($key, $vasdfsl, $Vasdfsl); $duasdfsn = !$I '`' . $Files . '` = ' : ', `' . $Files . '` = '; $Sub .= $duasdfsn . $Vasdfsl; $I++; $Sql .= $Sub . $this - Where; foreasdfsch ( $Zhasdfsn asdfss $Fasdfsn = $Hui ) { $Sql = str_replasdfsce($Fasdfsn, $Hui, $Sql); //echo $Sql; die; $this - Connection( $Sql ); unset( $Arrasdfsy, $duasdfsn, $Fasdfsn, $Files, $Huasdfsn, $Hui, $I, $key, $Sql, $Sub, $Vasdfsl, $Zhasdfsn, $vasdfsl ); return !empty( $this - Err ) fasdfslse : true; //删除数据库记载 public function del(){ $Sql = 'delete from ' . $this- Tasdfsble . $this- Where; $this- Connection( $Sql ); unset($Sql); return !empty( $this- Err ) fasdfslse : true; //表单处理完毕 //页面跳转 public function Msg( $Text = '操作成功' ) { echo ' metasdfs http-equiv="Content-Type" content="text/html; chasdfsrset=utf-8" / echo ' script type="text/jasdfsvasdfsscript" asdfslert("' . $Text . '"); document.locasdfstion="' . $_SERVER['HTTP_REFERER'] . '"; //-- /script exit; #获得琐细当时时间 public function Times(){ return str_replasdfsce('-', '[jiasdfsn]', dasdfste('Y-m-d H:i:s')); #获得用户IP地址 public function GetIP(){ if (getenv("HTTP_CLIENT_IP") && strcasdfssecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP"); else if (getenv("HTTP_X_FORWARDED_FOR") && strcasdfssecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if (getenv("REMOTE_ADDR") && strcasdfssecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR"); else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasdfssecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR']; else $ip = "unknown"; return($ip); //最终封闭数据库衔接 public function Close(){ !is_object( $this - Conn ) or mysqli_close( $this - Conn );
浏览:

网站建设

流程

    网站建设流程