Convert mysql php join to PDO join

I have a connection using mysql in php and you want to turn this into a pdo request, how to do it?

Also, how do I get the results of this query and display it.

Code below:

$query = "SELECT * FROM pages LEFT JOIN templates ON pages.template_id = templates.template_id WHERE pages.page_Title = '".$getVars['page']."'"; 

I'm new to PDO, so this may sound like a very simple question.

Thanks at Advance

+3
source share
1 answer

Why don't people even look at the PHP link for these basic questions? See http://be2.php.net/manual/en/pdo.connections.php . All this is there, you do not need to change anything for the request in order to start it with PDO.

However, you can try to use a prepared statement and pass the header 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);
    }
}
+3
source

Source: https://habr.com/ru/post/1769724/


All Articles