Home > Backend Development > PHP Tutorial > How to use PDO to modify data in PHP?

How to use PDO to modify data in PHP?

Guanhui
Release: 2023-04-08 18:26:02
Original
3134 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
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template