Summary of Mysqli Method test

Source: Internet
Author: User
Tags learn php mysql host mysql view

<?PHPclassMysqlcontrollerextendscontrollerbase{ Public $config=Array();  Public $mysql=NULL;  Public functionInitialize () {$this->config =Array(            ' Host ' = ' localhost:3306 ', ' username ' = ' daokrdb ', ' password ' = ' 123456 ', ' dbname ' = > ' Daokrdb ',        ); }     Public functionindexaction () {//Create a connection        $mysql=NewMysqli ($this->config[' Host '],$this->config[' username '),$this->config[' password '),$this->config[' dbname ']); /*Change db to World db*/        //$mysqli->select_db ("World");//You can use select_db to change the database//Check connection        if($mysql-connect_error) {             die("Connection failed:".)$mysql-connect_error); }Else{            $thread _id=$mysql-thread_id; Echo"MySQL host information:".$mysql->host_info. " <br/> "; Echo"MySQL View server information:".$mysql->server_info. " <br/> "; Echo"MySQL gets the last database query information:".$mysql->info. " <br/> "; Echo"MySQL gets the current system state:".$mysql-Stat()." <br/> "; Echo"MySQL is thread safe:".$mysql->thread_safe (). " <br> "; Echo"MySQL returns the thread ID of the current connection:".$thread _id." <br> "; $this-MySQL=$mysql; }        /*set the client character set*/        if(!$mysql->set_charset ("UTF8")) {            Echo("Set UTF8 Error:".)$mysql->error. " <br> "); } Else {            Echo("Currently set character sets:".)$mysql->character_set_name (). " <br> "); }                /*Kill current Connection thread*/        //$mysql->kill ($thread _id);        $this-Insert (); $this-Select (); $this-find (); $this-Delete (); $this-update (); $mysql-Close (); }    functionSelect () {$sql= "Select t.* from T_users T"; $result=$this-MySQL->query ($sql); if($result->num_rows>0){             while($row=$result-Fetch_assoc ()) {                Echo"Number:".$row[' ID ']. " Title: ".$row[' title ']. <br> "; }            $result-Close (); }    }    //Increase    functionInsert () {$sql= "INSERT into T_users (title, author,submission_date) VALUES (' John ', ' Doe ', Now ())"; if($this-MySQL->query ($sql) ===TRUE) {            Echo"New record insertion success <br/>"; } Else {            Echo"Error:".$sql. "<br>".$this-MySQL-error; }        $name= "Learn PHP"; $query= "Select title from T_users WHERE title=?"; $binduser=$this-MySQL->prepare ($query); if($binduser){            $binduser->bind_param (' s ',$name);//i-integer (integer) d-double (double-precision floating-point) s-string (string) b-blob (Binary large object: Binary Large Objects)            $binduser-execute (); $binduser->bind_result ($title); $binduser-fetch (); Echo"Bind_result Query succeeded:".$title." <br/> "; $binduser-Close (); }    }    //Delete    functionDelete () {$sql= ' Delete from t_users where title= ' d ' '; $result=$this-MySQL->query ($sql); if($result){            Echo"Delete Success <br>"; }Else{            Echo"Error:".$sql. "<br>".$this-MySQL-error; }    }    //Change    functionUpdate () {$sql= ' Update t_users set title= ' PHP webs ' where id=31 '; $result=$this-MySQL->query ($sql); if($result){            Echo"Update Success <br>"; }Else{            Echo"Error:".$sql. "<br>".$this-MySQL-error; }    }    }

Summary of Mysqli Method test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.