我试图找到一种方法,功能自动创建仅通过访问一个网址为DB-条目。 网址应该在每一个新的一天访问一次。创建自动创建一个新的数据库条目
这是我的职责,我想现在:
function createMedOne() {
$medid = "1";
$mname = "Name1";
$menh = "Amount 1";
$mtime = "17:23";
$mdte = date("Y-m-d");
$mhtml = '<tr class="" id="med1">
<td><p style="font-weight: bold;">Name1</p></td>
<td>Amount 1</td>
<td>Kl: 17:23</td>
<td><button type="button" class="btn btn-warning btn-sm" style="float: right;">Sign</button></td>
</tr>';
$reg_med->addmed($medid,$mname,$menh,$mtime,$mdte,$mhtml);
}
createMedOne();
其它功能:
function addmed($medid,$mname,$menh,$mtime,$mdte,$mhtml)
{
try
{
$stmt = $this->conn->prepare("INSERT INTO tbl_med(medID,medName,medEnh,medTime,medDate,medHtml)
VALUES(:med_Id, :med_name, :med_enh, :med_time, :med_date, :med_html)");
$stmt->bindparam(":med_Id",$medid); //id of the med
$stmt->bindparam(":med_name",$mname); //name of the med
$stmt->bindparam(":med_enh",$menh); //the amount
$stmt->bindparam(":med_time",$mtime); //When to give med
$stmt->bindparam(":med_date",$mdte); //date
$stmt->bindparam(":med_html",$mhtml); //the html-code to generate content
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
当我访问的URL我收到以下错误:
Fatal error: Call to a member function addmed() on null in test2.php on line 20
它指的是函数createMedOne,但我找不到我错过了某些东西,但显然我有。
我被自己处理过,可能是我可以帮你吗? –
它是一个[可变范围(http://stackoverflow.com/q/16959576/1415724) –
[PHP呼叫类方法/函数(的可能的复制http://stackoverflow.com/questions/15499513/php-call -class-method-function) – miken32