gpt4 book ai didi

php - 无法从mysql数据库加载数据

转载 作者:行者123 更新时间:2023-11-29 23:26:07 24 4
gpt4 key购买 nike

这是我的问题。我正在设置日历,但在从 sqlite 数据库切换到 mysql 数据库时遇到问题。

问题是当事件从 mysql 传递过来时,DayPilot 没有加载事件。非常感谢任何帮助。谢谢。

<?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();
}

}

?>

最佳答案

试试这个

<?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);


foreach ($messages as $m) {
$name = $m['name'];
$start = $m['start'];
$end = $m['end'];
$resource = $m['resource'];
}

$stmt->bindParam(':name', $name);
$stmt->bindParam(':start', $start);
$stmt->bindParam(':end', $end);
$stmt->bindParam(':resource', $resource);
$stmt->execute();

}

?>

我还没有测试过,但希望它能解决您的问题。

关于php - 无法从mysql数据库加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26947718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com