Two examples of preprocessing operations for PHP mysqli extension libraries

Source: Internet
Author: User
This article shares the PHP use mysqli Extension Library for preprocessing operations of two examples, interested in studying the use of mysqli friends, you can refer to the study, will certainly be helpful.

Example 1, preprocessing technology using MYSQLI Extension Library mysqli stmt add 3 users to a database

     Connect_error) {die ($mysqli->conncet_error);} 2. Create precompiled object $sql= "insert into User1 (name,password,email,age) VALUES (?,?,?,?)"; $mysqli _stmt= $mysqli->prepare ($sql);//binding parameter Bbs.it-home.org$name= "Small Fang";//$password =md5 ("ffff"); $password = " 123456 "; $email =" xiaofang@jbxue.com "; $age =18;//parameter binding? The type and order of the number should be consistent $mysqli_stmt->bind_param ("SSSI", $name, $password, $email, $age);//execute $b= $mysqli _stmt->execute () ;//Continue to add $name= "Xiao Yang"; $password = "123456"; $email = "xiaoyang@jbxue.com"; $age =18;//parameter binding? The type and order of the number should be consistent $mysqli_stmt->bind_param ("SSSI", $name, $password, $email, $age);//execute $b= $mysqli _stmt->execute () ;//Continue to add $name= "small g"; $password = "123456"; $email = "xiaoG@jbxue.com"; $age =18;//parameter binding? The type and order of the number should be consistent $mysqli_stmt->bind_param ("SSSI", $name, $password, $email, $age);//execute $b= $mysqli _stmt->execute () if (! $b) {echo "operation failed". $mysqli _stmt->error;} Else{echo "Operation succeeded";} Turn off precompiled $mysqli_stmt->close (); $mysqli->close ();? >

Example 2, using pre-processing query id>5 User ID name email

 
      The user ID of 5 is name email$mysqli=new mysqli ("localhost", "root", "root", "test"), if ($mysqli->connect_error) {die ($mysqli- >connect_error);} Create precompiled Object $sql= "select Id,name,email from User1 where Id>?"; $mysqli _stmt= $mysqli->prepare ($sql) $id =5;//binding parameter $mysqli_stmt->bind_param ("I", $id);//bind result set $mysqli_stmt- >bind_result ($id, $name, $email);//execute $mysqli_stmt->execute ();//Remove the bound value while ($mysqli _stmt->fetch ()) {echo "
$id--$name--$email ";} Close resource//release result $mysqli_stmt->free_result ();//close with compile statement $mysqli_stmt->close ();//close connection $mysqli->close (); >
  • 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.