Blogger Information
Blog 38
fans 0
comment 0
visits 25308
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第七课—类与对象 2018年8月29日
空白
Original
679 people have browsed it
  1. 类是对象的模板,对象是类的实例

  2. MySQL curd

    2.png

    3.连接数据库

    

实例

<!-- confing -->
<?php
$db = [
   'host' => '127.0.0.1',
   // 用户名
   'user' => 'root',
   // 密码
   'pass' => '',
   // 数据库名称
   'name' => 'test',
   // 字符集
   'charset' => 'utf8',
];

运行实例 »

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

实例

<?php

// 导入数据库配置文件
require 'confing.php';
// 关闭警告
error_reporting(E_ALL ^E_WARNING);
// 创建数据库连接
$sql = new mysqli($db['host'], $db['user'], $db['pass'], $db['name']);
// 判断是否连接成功
if ($sql -> connect_errno) {
	//自定义提示信息
	die('连接错误'.$sql -> connect_errno.$sql -> connect_error);
}
echo '<h2>数据库连接成功</h2>';
// 设置数据库字符集
$sql -> set_charset($db['charset']);

运行实例 »

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

3.png

手写

IMG_20180831_100018.jpg


总结:

    1.MySQL插入数据 insert table_name ( field1, field2,...fieldN ) values ( value1, value2,...valueN );

    2.MySQL查询数据 select * from table_name where  id=num

    3.MySQL更新数据 update table_name set field1=new_value1,field2=new_value2,fieldN=new_valueN where id=num

    4.MySQL删除数据 delete from table_name where id=num

    5.数据库连接 new mysqli($db['host'], $db['user'], $db['pass'], $db['name']);

    6.判断是否连接成功使用 connect_errno 属性

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