tags:

views:

23

answers:

1

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

A: 

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);
    }
}
wimvds
I did have a look at the php reference but was stuck on how to write the actual query. I have done other queries in pdo but this was the first time I am trying to do a join in pdo.
CoderX