<?php
$mysqli = new mysqli('localhost' 'root', "", 'scandi');
// check connection
if ($mysqli->connect_error) {
trigger_error('Database connection failed: '.$mysqli-> connect_error , E_ USER_ERROR);
}
$regid = mysqli_real_escape_string($mysqli, $_POST['regid']);
$startdate = mysqli_real_escape_string($mysqli, $_POST['startdate']);
$enddate = mysqli_real_escape_string($mysqli, $_POST['enddate']);
$query="DROP PROCEDURE IF EXISTS filldates ;
CREATE PROCEDURE filldates(dateStart DATE, dateEnd DATE)
BEGIN
WHILE dateStart <= dateEnd
DO
INSERT INTO mydates (did,_date,regid) VALUES ('1',dateStart,'$regid');
SET dateStart = date_add(dateStart, INTERVAL 7 DAY);
END WHILE;
END;
CALL filldates('$startdate','$enddate')";
if (mysqli_query($mysqli, $query)) {
do {
if ($result = mysqli_store_result($mysqli)) {
mysqli_free_result ($result);
}
if (mysqli_more_results ($mysqli)) {
}
}while(mysqli_next_result ($mysqli));
}
mysqli_close($mysqli)
?>
我想在表(mydates)中存储日期,$regid、$startdate、$enddate 由用户提供,'did' 是 auto_increament。上面没有 mysqli 的代码在 CLI 中运行良好并将日期存储在表中,但是当我尝试在 php 页面中使用它时失败。有没有人帮忙?