Answer the question
In order to leave comments, you need to log in
Bulk adding records in mysqli?
Good afternoon, how to make an array in the form of having .
When you enter a new line in c - a new entry in the mysqli database.
In one word:
As I understand it, the array in the request goes:
INSERT INTO tbl_name (id, code, expire, type, value, min_order_price, single, usages) VALUES(1, 2, 3, 4, 5, 6, 7, 8, 9), (1, 2, 3, 4, 5, 6, 7, 8, 9), (1, 2, 3, 4, 5, 6, 7, 8, 9);
if($this->request->post("new_code")){
$new_expire = $this->request->post('new_expire');
$new_coupon = new stdClass();
$new_coupon->id = $this->request->post('new_id', 'integer');
$new_coupon->code = $this->request->post('new_code', 'string');
if(!empty($new_expire)) {
$new_coupon->expire = date('Y-m-d', strtotime($new_expire));
} else {
$new_coupon->expire = null;
}
$new_coupon->value = $this->request->post('new_value', 'float');
$new_coupon->type = $this->request->post('new_type', 'string');
$new_coupon->min_order_price = $this->request->post('new_min_order_price', 'float');
$new_coupon->single = $this->request->post('new_single', 'float');
// Не допустить одинаковые URL разделов.
if(($a = $this->coupons->get_coupon((string)$new_coupon->code)) && $a->id != $new_coupon->id) {
$this->design->assign('message_error', 'code_exists');
} elseif(empty($new_coupon->code)) {
$this->design->assign('message_error', 'empty_code');
} else {
$new_coupon->id = $this->coupons->add_coupon($new_coupon);
$new_coupon = $this->coupons->get_coupon($new_coupon->id);
$this->design->assign('message_success', 'added');
}
}
public function add_coupon($coupon) {
if(empty($coupon->single)) {
$coupon->single = 0;
}
$query = $this->db->placehold("INSERT INTO __coupons SET ?%", $coupon);
if(!$this->db->query($query)) {
return false;
} else {
return $this->db->insert_id();
}
}
Answer the question
In order to leave comments, you need to log in
You do not have mysqli, but some kind of crooked division.
And I'll show you how to do it in mysqli
$data = [
['[email protected]', password_hash('password1', PASSWORD_DEFAULT)],
['[email protected]', password_hash('password2', PASSWORD_DEFAULT)],
];
$stmt = $mysqli->prepare("INSERT INTO users VALUES (null,?,?)");
$mysqli->begin_transaction();
foreach ($data as $row) {
$stmt->bind_param("ss", ...$row);
$stmt->execute();
}
$mysqli->commit();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question