-1
我想知道在类中创建函数是否有一种很好的方法,以便于插入/删除/更新mysql查询。在INSERT,DELETE和UPDATE类中创建动态函数
例如
比方说,我有一个包含12行的表,我想和两个值插入查询从另一个类中。插入函数的外观如何?我希望这个函数能够处理任何数量的值。
function addUser($email, $password) {
$values = array(
"email" => $email,
"password" => $password
);
$table = 'users';
$query = $mysql->insert($values, $table);
}
function insert($values, $table) {
// what would this look like? (note: this function is within another class.
}
我希望最终的和预处理语句执行查询,像:
if($stmt = $this->db->prepare($query)) {
$stmt->bind_param('ss', $email, $password);
$stmt->execute();
if($stmt->fetch()) {
$stmt->close();
return true;
}
}
不要这样做。这是个好主意,但最好不要编写自己的工具,而应该使用已经存在的,例如教义。 –