它可以在我的本地主机上运行,但不能在服务器上运行。这是否意味着数据库根本没有连接,还是语句中出现错误?
$submission = $_POST['submit'];
$decode = json_decode($submission, true);
try {
$pdo = new PDO('mysql:localhost;dbname=database', 'username', 'password');
} catch(PDOException $e){
echo 'PDO Exception: '.$e->getMessage();
die();
}
class QueryBuilder {
protected $pdo;
public function __construct($pdo){
$this->pdo = $pdo;
}
public function insert($parameters){
$sql = "insert into tableName ('entry', 'author', 'email', 'sign', 'month') values (:entry, :author, :email, :sign, :month)";
$statement = $this->pdo->prepare($sql);
try {
$statement->execute($parameters);
} catch (Exception $e) {
die($e->getMessage());
}
}
}
$query = new QueryBuilder($pdo);
$query->insert($decode);
我什至尝试了一个表清除语句,它也无济于事...
public function clear(){
try {
$statement = $this->pdo->prepare("truncate table submissions");
$statement->execute();
} catch (Exception $e) {
die($e->getMessage());
}
}
$query->clear();