I will go to 51job for an interview today .. The examiner asked about the MySQL variable binding concept.
This is because the project has never been used before, and the MySQL research is insufficient. You just need to ask--back to Baidu and try again.
It is really a good thing.
The availability of variable binding is unquestionable. The 5% performance improvement on large systems is good. In addition, the security of variable binding can well regulate the verification of SQL statements, avoid writing verification statements independently,
Bind variables is recommended.
<? PHP $ Mysqli = New Mysqli ("localhost", "root", "123321", "test" ); $ Sql1 = "Set @ profiling = 1" ; $ Result1 =$ Mysqli -> Query ( $ Sql1 ); // Prepare a statement on the server and insert the statement. $ SQL = "Insert into T (name, sex) values (?,?) " ; $ Stmt = $ Mysqli -> Prepare ( $ SQL ); // Each placeholder? Pass number (BIND parameter) I D S B $ Stmt -> Bind_param ("Si ", $ Name , $ Sex ); $ Name = "Andy" ; $ Sex = 0 ; // Run $ Stmt -> Execute (); $ Name = "Mandy" ; $ Sex = 1 ; // Run $ Stmt -> Execute (); $ Name = "Michael" ; $ Sex = 0 ; // Run $ Stmt -> Execute (); $ Name = "Happy"; $ Sex = 1 ; // Run $ Stmt -> Execute (); $ Name = "Php" ; $ Sex = 1 ; // Run $ Stmt ->Execute (); $ Name = "MySQL" ; $ Sex = 1 ; // Run $ Stmt -> Execute (); $ Name = "Linux" ; $ Sex = 1 ; // Run $ Stmt -> Execute (); $ Name = "Oracle" ; $ Sex = 1 ; // Run $ Stmt -> Execute (); $ Name = "Unix" ; $ Sex = 1; // Run $ Stmt -> Execute (); $ Name = "Cisco" ; $ Sex = 1 ; // Run $ Stmt -> Execute (); $ Stmt ->Close (); $ Sql2 = "Show profiles" ; $ Result2 = $ Mysqli -> Query ( $ Sql2 ); Echo '<Table border = 1 align = "center" width = 800>' ; While ( $ Rows = $ Result2 ->Fetch_assoc ()){ Echo '<Tr align = "center">' ; Foreach ( $ Rows As $ Value ){ Echo '<TD> '. $ Value . '</TD>' ;} Echo '</Tr>' ; $ I = 0 ; $ I = $ I + $ Rows ["Duration" ];} Echo '</Table>' ; Echo $ I ; ?>
<?PHP $ Mysqli = New Mysqli ("localhost", "root", "123321", "test" ); $ Sql1 = "Set @ profiling = 1" ; $ Result1 = $ Mysqli -> Query ( $ Sql1 ); $ Nobind = Array ("Insert into T (name, sex) values ('andy ', 0)", "insert into T (name, sex) values ('mandy', 1 )", "insert into T (name, sex) values ('Michael ', 0)", "insert into T (name, sex) values ('Happy', 0 )", "insert into T (name, sex) values ('php', 0)", "insert into T (name, sex) values ('mysql, 0 )", "insert into T (name, sex) values ('linux ', 0)", "insert into T (name, sex) values ('oracle', 0 )", "insert into T (name, sex) values ('cisco ', 0)", "insert into T (name, sex) values ('unix', 0 )" ); Foreach ( $ Nobind As $ SQL ){ Echo $ SQL ; $ Result = $ Mysqli -> Query ( $ SQL );} $ Sql2 = "Show profiles" ; $ Result2 = $ Mysqli -> Query ( $ Sql2 ); Echo '<Table border = 1 align = "center" width = 800>' ; While ( $ Rows = $ Result2 -> Fetch_assoc ()){ Echo '<Tr align = "center">' ; Foreach ( $ Rows As $ Value ){ Echo '<TD> '. $ Value . '</TD>' ;} Echo '</Tr>' ; $ I = 0 ; $ I = $ I +$ Rows ["Duration" ];} Echo '</Table>' ; Echo $ I ; $ Mysqli -> Close (); ?>
This article is from "fenghao.cn's soft .."