我试图从两个表中检索数据并回显结果,sql 似乎是正确的,但它告诉我参数无效。这是我的代码:
// Retrieve all information related to this post
function get_post_data($post_id){
//test the connection
try{
//connect to the database
$dbh = new PDO("mysql:host=localhost;dbname=mjbox","root", "usbw");
//if there is an error catch it here
} catch( PDOException $e ) {
//display the error
echo $e->getMessage();
}
$sql = 'SELECT * FROM mjbox_images JOIN mjbox_posts USING (post_id) WHERE post_id = $post_id';
$result = $dbh->query( $sql );
foreach($result as $row):
echo $row['img_id'];
endforeach;
}