PHP database connection class

后端 未结 6 1981
名媛妹妹
名媛妹妹 2020-12-08 05:29

I am trying to get a users ID from a database within a class, but I have very little to no experience with classes, how could I go about getting the uid from the DB and then

6条回答
  •  悲哀的现实
    2020-12-08 06:35

    Try following:

    ini_set("display_errors", 'off');
        ini_set("error_reporting",E_ALL);   
    
    class myclass {
        function myclass()   {    
            $user = "root";
            $pass = "";
            $server = "localhost";
            $dbase = "";
    
               $conn = mysql_connect($server,$user,$pass);
               if(!$conn)
            {
                $this->error("Connection attempt failed");
            }
            if(!mysql_select_db($dbase,$conn))
            {
                $this->error("Dbase Select failed");
            }
            $this->CONN = $conn;
            return true;
        }
        function close()   {   
            $conn = $this->CONN ;
            $close = mysql_close($conn);
            if(!$close)
            {
                $this->error("Connection close failed");
            }
            return true;
        }       function sql_query($sql="")   {    
            if(empty($sql))
            {
                return false;
            }
            if(empty($this->CONN))
            {
                return false;
            }
            $conn = $this->CONN;
            $results = mysql_query($sql,$conn) or die("Query Failed..
    " . mysql_error()); if(!$results) { $message = "Bad Query !"; $this->error($message); return false; } if(!(eregi("^select",$sql) || eregi("^show",$sql))) { return true; } else { $count = 0; $data = array(); while($row = mysql_fetch_array($results)) { $data[$count] = $row; $count++; } mysql_free_result($results); return $data; } } } $obj = new myclass(); $obj->sql_query("");

提交回复
热议问题