对于我的生活,我似乎无法让这个简单的插入查询工作:
try {
// Connect to database
$dbh = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
// Create an array of all data to be inserted
$data = array(':id' => 'null',
':name' => $name,
':location' => $loc,
':latitude' => $lat,
':longitude' => $lon,
':website' => $web,
':bandcamp' => $bandcamp,
':facebook' => $facebook,
':bio' => $bio,
':image' => $image,
':updated' => 'null');
// Create sql statement
$sql = 'INSERT INTO artists VALUES (:id, :name, :location, :latitude, :longitude, :website, :bandcamp, :facebook, :bio, :image, :updated)';
// Run query
$query = $dbh->prepare($sql);
$query->execute($data);
// Disconnect from database
$dbh = null;
}
catch(PDOException $e) {
echo $e->getMessage();
}
数据没有被插入到表中,我没有收到任何错误消息。我在这里错过了什么吗?