PHP mysqli extension library Preprocessing Technology

Source: Internet
Author: User

1. Use mysqli extended library Preprocessing Technology mysqli stmt to add three users to the database

<? PHP  //  Mysqli extended library Preprocessing Technology mysqli stmt adds three users to the database  //  1. Create a mysqli object $ Mysqli = New Mysqli ( "  Localhost  " , "  Root  " , "  Root " , "  Test  "  );  If ($ Mysqli-> Connect_error) {die ($ mysqli -> Conncet_error );}  //  2. Create a pre-compiled object $ SQL = "  Insert into user1 (name, password, email, age) values (?,?,?,?)  "  ; $ Mysqli_stmt = $ Mysqli->Prepare ($ SQL );  //  Bind Parameters $ Name = "  Xiaofang  "  ;
// $ Password = MD5 ("ffff"); $ Password = " 123456 " ; $ Email = " Xiaofang@126.com " ; $ Age =18 ; // Parameter binding->? Number Assignment here the type and order must be consistent $ Mysqli_stmt-> bind_param ( " SSSI " , $ Name, $ password, $ email, $ age ); // Run $ B = $ mysqli_stmt-> Execute (); // Add more $ Name = " Xiao Yang " ; $ Password = " 123456 " ; $ Email = " Xiaoyang@126.com " ; $ Age = 18 ; // Parameter binding->? Number Assignment here the type and order must be consistent $ Mysqli_stmt-> bind_param (" SSSI " , $ Name, $ password, $ email, $ age ); // Run $ B = $ mysqli_stmt-> Execute (); // Add more $ Name = " Small g " ; $ Password = " 123456 " ; $ Email = " XiaoG@126.com " ; $ Age = 18 ; // Parameter binding->? Number Assignment here the type and order must be consistent $ Mysqli_stmt-> bind_param ( " SSSI " , $ Name, $ password, $ email, $ age ); // Run $ B = $ mysqli_stmt-> Execute (); If (! $ B) {echo " Operation failed " . $ Mysqli_stmt-> Error ;} Else {Echo " Operation successful " ;} // Disable pre-Compilation $ Mysqli_stmt-> Close (); $ mysqli -> Close (); ?>

2. Use pre-processing to query user ID name email with ID> 5

<? PHP  //  Use the pre-processed query ID> 5 user ID name email      $ Mysqli = New Mysqli ("localhost", "root", "root", "test" );  If ( $ Mysqli -> Connect_error ){ Die ( $ Mysqli -> Connect_error );}  //  Create a pre-compiled object      $ SQL = "Select ID, name, email from user1 where ID>? " ;  $ Mysqli_stmt = $ Mysqli -> Prepare ( $ SQL  );  $ ID = 5 ;  // Bind Parameters      $ Mysqli_stmt -> Bind_param ("I ", $ ID  );  //  Bind result set      $ Mysqli_stmt -> Bind_result ( $ ID , $ Name , $ Email  );  //  Run      $ Mysqli_stmt -> Execute (); //  Retrieve the bound value      While ( $ Mysqli_stmt -> Fetch ()){  Echo "<Br/> $ ID -- $ Name -- $ Email " ;}  //  Close resource // release result      $ Mysqli_stmt -> Free_result (); //  Close and compile statements      $ 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.