Home > Article > Backend Development > How to use PDO to modify data in PHP?
#How to use PDO to modify data in PHP?
First connect to the database and instantiate the PDO object;
$dbms = 'mysql'; $user = 'root'; $pwd = '12345678'; $dbName = 'ceshi'; $host = 'localhost'; $charset = 'utf8'; $dsn = "$dbms:host=$host;dbname=$dbName;charset=$charset"; try { $pdo = new PDO( $dsn, $user, $pwd ); } catch ( Exception $e ) { echo $e->getMessage(); }
Then write a SQL statement template; then use the "prepare()" method to prepare the SQL statement Processing;
$sql = "select * from dunling_chat where id=? "; //准备sql模板 $stmt = $pdo->prepare( $sql );
Finally bind parameters and execute SQL.
$id = '1'; //绑定参数 $stmt->bindValue( 1, $id ); //执行预处理语句 $stmt->execute();
Recommended tutorial: "PHP Tutorial"
The above is the detailed content of How to use PDO to modify data in PHP?. For more information, please follow other related articles on the PHP Chinese website!