Blogger Information
Blog 25
fans 0
comment 0
visits 15814
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0724数据库作业
杨发国的博客
Original
911 people have browsed it

作业1:写出MySQL数据库基本语法

创建数据库

CREATE DATABASE ‘数据库名称‘

创建数据表

CREATE TABLE '数据表名称’

1,增加语句

INSERT INTO '数据表’('字段1','字段2',.......) VALUES('值1','值2',.......)

2,删除语句

DELETE FROM '数据表' WHERE 删除条件

3,更新语句

UPDATE  '数据表' SET '字段1'='值1','字段2'='值2',........ WHERE 更新条件 

4,查询语句

SELECT '字段列表' FROM '数据表名' WHERE 查询条件

作业2:

实例

<?php
$db= [
    'type' => 'mysql',
    'host' => '127.0.0.1',
    'dbname' => 'php',
    'username' => 'root',
    'password' => 'root'
];
// 连接数据库:
$dsn = "{$db['type']}:host={$db['host']};dbname={$db['dbname']}";
$username = $db['username'];
$password = $db['password'];
$pdo = new PDO($dsn, $username, $password);
//  创建SQL语句对象: 预处理对象,新增记录
$stmt=$pdo->prepare( 'INSERT INTO `user`SET `name`=:name,`age`=:age');
//执行SQL语句
$stmt->execute(['name'=>'杨发国', 'age'=>39]);
echo '成功的添加' . $stmt->rowCount(). '条记录, 主键:'. $pdo->lastInsertId();

//关闭连接:
//$pdo = null;

$del = $pdo->prepare( 'DELETE FROM `user` WHERE `id`=:id');
$del->execute(['id'=>3]);
echo '成功的删除' . $del->rowCount(). '条记录, 主键:'. $pdo->lastInsertId();
//关闭连接:
$pdo = null;

运行实例 »

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

 

1.png

 

2.png3.png

4.png

Correction status:qualified

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