Convert mysql php join to PDO join
I have a join using mysql in php and want to turn that into a pdo query how do i do that?
Also how do I get the results of this query and display it.
Code is below:开发者_高级运维
$query = "SELECT * FROM pages LEFT JOIN templates ON pages.template_id = templates.template_id WHERE pages.page_Title = '".$getVars['page']."'";
I am new to PDO so this might sound like a very basic question.
Thanks in Advance
Why don't people even look at the PHP reference for these basic questions? See http://be2.php.net/manual/en/pdo.connections.php. It's all there, you don't have to change anything to the query in order to run it with PDO.
You could however try using a prepared statement, and pass the title as a parameter :
$dbh = new PDO('mysql:host=localhost;dbname=database', $user, $pass);
$stmt = $dbh->prepare("SELECT * FROM pages LEFT JOIN templates ON pages.template_id = templates.template_id WHERE pages.page_Title = ?");
if ($stmt->execute(array($getVars['page']))) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
精彩评论