0
這是我的問題。我正在設置日曆,並且無法從sqlite數據庫切換到我的mysql數據庫。無法從mysql數據庫加載數據
問題是DayPilot在從mysql傳遞時沒有加載事件。非常感謝任何幫助。謝謝。
<?php
//$db_exists = file_exists("daypilot1.sqlite");
//$db = new PDO('sqlite:daypilot.sqlite'); This works
// i tried these two ways. both of them did not work.
$db = new PDO("mysql:host=localhost;dbname=his", "root", "123");
/* $servername = "localhost";
$username = "root";
$password = "123";
try {
$db = new PDO("mysql:host=$servername;dbname=his", $username, $password);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
*/
if (!$db) {
//create the database
$db->exec("CREATE TABLE IF NOT EXISTS events (
id INTEGER PRIMARY KEY,
name TEXT,
start DATETIME,
end DATETIME,
resource VARCHAR(30))");
$messages = array(
array('name' => 'Event 1',
'start' => '2013-05-09T00:00:00',
'end' => '2013-05-09T10:00:00',
'resource' => 'B')
);
$insert = "INSERT INTO events (name, start, end, resource) VALUES (:name, :start, :end, :resource)";
$stmt = $db->prepare($insert);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':start', $start);
$stmt->bindParam(':end', $end);
$stmt->bindParam(':resource', $resource);
foreach ($messages as $m) {
$name = $m['name'];
$start = $m['start'];
$end = $m['end'];
$resource = $m['resource'];
$stmt->execute();
}
}
?>
此代碼中的更改是什麼?這是原始代碼 – Priyankara
Anayway尋求你的迴應 – Priyankara
@ user2781812'$ stmt-> execute();'從循環中退出並且'$ stmt-> bindParam'在循環之後。 –