How to use PDO to modify data in PHP?

Guanhui
Release: 2023-04-08 18:26:02
Original
3023 people have browsed it

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();
}
Copy after login

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 );
Copy after login

Finally bind parameters and execute SQL.

$id = '1';
//绑定参数
$stmt->bindValue( 1, $id );
//执行预处理语句
$stmt->execute();
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!