Blogger Information
Blog 18
fans 0
comment 0
visits 13492
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PDO增删改-3.21
太早的博客
Original
736 people have browsed it

备注:向表格中插入新的行

实例

<?php
	$dsn = 'mysql:host=127.0.0.1;dbname=van;charset=utf8;port=3306;';
	$dbname = 'root';
	$dbpassword = 'root';
	$pdo = new PDO($dsn,$dbname,$dbpassword);
	$sql = 'INSERT INTO `staff` (`name`,`age`,`sex`,`position`,`mobile`,`hiredate`)';
	$sql .= ' VALUES (:name, :age, :sex, :position, :mobile, :hiredate)';
	$stmt = $pdo->prepare($sql);
	$k = ['name','age','sex','position','mobile','hiredate'];
	$v = ['沐泓',13,'男','丐帮帮主','13333333333',time()];
	$d = array_combine($k,$v);
	$stmt->execute($d);
	echo $stmt->rowCount();

运行实例 »

点击 "运行实例" 按钮查看在线实例


备注:删除表中的行

实例

<?php
	$dsn = 'mysql:host=127.0.0.1;dbname=van;charset=utf8;port=3306;';
	$dbname = 'root';
	$dbpassword = 'root';
	$pdo = new PDO($dsn,$dbname,$dbpassword);
	$sql = 'DELETE FROM `staff` WHERE `name`=:name';
	$stmt = $pdo->prepare($sql);
	$stmt->execute(['name'=>'沐泓']);
    echo $stmt->rowCount();

运行实例 »

点击 "运行实例" 按钮查看在线实例


备注:修改表中的数据

实例

<?php
	$dsn = 'mysql:host=127.0.0.1;dbname=van;charset=utf8;port=3306;';
	$dbname = 'root';
	$dbpassword = 'root';
	$pdo = new PDO($dsn,$dbname,$dbpassword);
	$sql = 'UPDATE `staff` SET `position` = :position WHERE `id`=:id';
	$stmt = $pdo->prepare($sql);
	$stmt->execute(['position'=>'前台', 'id'=>5]);
	echo $stmt->rowCount();

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post