zoukankan      html  css  js  c++  java
  • 继续封装DBDA.php 加入ajax

    <?php
    
    class DBDA
    {
        public $host = "localhost"; //服务器地址
        public $uid = "root"; //数据库的用户名
        public $pwd = "123456"; //数据库的密码
        
        //执行SQL语句,返回相应结果的函数
        //$sql是要执行的SQL语句
        //$type是SQL语句的类型,0代表增删改,1代表查询
        //$db代表要操作的数据库
        public function Query($sql,$type=1,$db="xinjian")
        {
            //造连接对象
            $conn = new MySQLi($this->host,$this->uid,$this->pwd,$db);
            
            //判断连接是否成功
            !mysqli_connect_error() or die("连接失败!");
            
            //执行SQL语句
            $result = $conn->query($sql);
            
            //判断SQL语句类型
            if($type==1)
            {
                //如果是查询语句返回结果集的二维数组
                return $result->fetch_all();
            }
            else
            {
                //如果是其他语句,返回true或false
                return $result;
            }
        }
        
        public function ajaxQuery($sql,$type=1,$db="xinjian")
        {
            //造连接对象
            $conn = new MySQLi($this->host,$this->uid,$this->pwd,$db);
            
            //判断连接是否成功
            !mysqli_connect_error() or die("连接失败!");
            
            //执行SQL语句
            $result = $conn->query($sql);
            
            $attr = $result->fetch_all();
            if($type==1)
            {
            $str ="";
            
            for($i=0;$i<count($attr);$i++)
            {
                
                for($j=0;$j<count($attr[$i]);$j++)
                {
                    $str = $str.$attr[$i][$j];
                    $str = $str."^";
                }
                $str = substr($str,0,strlen($str)-1);
                $str = $str."|";
            }
            $str = substr($str,0,strlen($str)-1);
            return $str;
            }
            else
            {
                return $result;
                }
        
        }
    }
  • 相关阅读:
    268. Missing Number
    217. Contains Duplicate
    189. Rotate Array
    Two Sum II
    122. Best Time to Buy and Sell Stock II
    169. Majority Element
    C# ConfigurationManager不存在问题解决
    C# sqlhelper
    C#基础
    数据库事务日志已满的解决办法
  • 原文地址:https://www.cnblogs.com/zhanghaozhe8462/p/5362062.html
Copyright © 2011-2022 走看看