// 拼装sql语句,重点在于--->'".$username."'
$this->sql = "insert into $this->table (username, password) values ('".$username."', $password)";
return $this;
}
// 删除数据
public function delete($id)
{
$this->action = 'other';
$this->sql = "delete from $this->table where id = $id";
return $this;
}
/
/ 修改数据
public function update($id, $username, $password)
{
$this->action = 'other';
$this->sql = "update $this->table set username='".$username."', password=$password where id = $id";        return $this;
}
// 之所以名称不⽤query是为了仍然可以使⽤mysqli类的query⽅法执⾏sql
public function query2()
{
// 执⾏语句
$result = $this->query($this->sql);
// 判断⽤户是什么操作
if ($this->action == 'select') {
$data = [];
// 解析查询数据
foreach ($result as $key => $value) {
$two_data = [];
foreach ($value as $two_key => $two_value) {
$two_data[$two_key] = $two_value;
}
$data[$key] = $two_data;
}
return $data;
} else {
if($result) {
return $result;
} else {
// 输出语句错误信息
手机unknown是什么意思echo $this->error;
return false;
}
}
}
}
// 建⽴与数据库的连接
$db = new MysqliClass('studymysqli');
// 设置要操作的表
$db->table = 'mysqli_class';
// 1. 查询数据
// $result = $db->select()->query2();
// var_dump($result);
// 2. 添加数据,⽤时间戳替代密码,⽤来判断是否成功添加
// $result = $db->insert('测试姓名', time())->query2();
// var_dump($result);
/
/ 3. 修改数据,
// 参数解释,唯⼀标识ID, ⽤户名称username, ⽤户密码password
// $result = $db->update(2, '修改⽤户名称', time())->query2();