我发现了一个日历脚本,就像我的其他文件一样,我希望它们运行一个config.php文件。到目前为止,每个脚本都有,尽管我发现了一个用PHP PDO编写的日历脚本,但我编写了相同的语言,但我尝试并包含config.php,尽管由于某种原因它不起作用。
脚本的原始代码:[有效]
<?php
$id = $_POST['id'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
try {
$bdd = new PDO('mysql:host=localhost;dbname=database2', 'root', 'mypassword');
} catch(Exception $e) {
exit('Unable to connect to database.');
}
// update the records
$sql = "UPDATE evenement SET title=?, start=?, end=? WHERE id=?";
$q = $dbh->prepare($sql);
$q->execu
te(array($title,$start,$end,$id));
?>
我对剧本的编辑:
<?php
include "../inc/config.php";
$id = $_POST['id'];
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
// update the records
$sql = "UPDATE evenement SET title=?, start=?, end=? WHERE id=?";
$q = $dbh->prepare($sql);
$q->execute(array($title,$start,$end,$id));
?>
Config.php
<?php
$hostname = 'localhost';
$username = 'root';
$password = 'mypassword';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=database2", $username, $password);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>