Php implements PDO-based preprocessing example and pdo preprocessing example
This example describes how to implement PDO-based preprocessing in php. We will share this with you for your reference. The details are as follows:
$ Servername = "localhost"; $ username = "root"; $ password = "admin"; // $ dbname is my test database $ dbname = "test "; try {$ conn = new PDO ("mysql: host = $ servername; dbname = $ dbname", $ username, $ password ); // set pdo error exception handling $ conn-> setAttribute (PDO: ATTR_ERRMODE, PDO: ERRMODE_EXCEPTION ); // pre-process the SQL statement and bind the parameter $ stmt = $ conn-> prepare ("INSERT INTO user (user_first, user_last, age) VALUES (: user_first,: user_last,: age) "); $ stmt-> bindParam (": user_first ", $ u Ser_first); $ stmt-> bindParam (": user_last", $ user_last); $ stmt-> bindParam (": age", $ age ); // insert record to be executed $ user_first = "xiao"; $ user_last = "liang"; $ age = 15; $ stmt-> execute (); // insert record to be executed $ user_first = "xiao"; $ user_last = "cheng"; $ age = 23; $ stmt-> execute (); echo "News record created successfully! ";} Catch (PDOException $ e) {echo" Error: ". $ e-> getMessage ();} $ conn = null;