Let me rephrase and simplify my question.
I have a database `mydb` with the table `metatags` having 3 columns: `page_id`, `page_url`, `page_title`.
When the pages are created dynamically-I'm using `page_id` as a base to supply different data, values from different rows of database to different webpages.
$page_id = filter_input(INPUT_GET, 'page_id', FILTER_VALIDATE_INT);
if (!$page_id) {
include '../errors/page-not-found.php';
}
$sql = "SELECT page_id, page_title FROM metatags WHERE page_id=:page_id;";
$metatags= pdo($pdo, $sql, [$page_id])->fetch();
if (!$metatags) {
include '../errors/page-not-found.php';
}
But, for static pages I have to use URL (I think) as a base, to make database to know which row of data to supply to the open webpage.
And that's my problem: how to query those rows based on url.
I'm started with connection:
<?php
try {
$pdo = new PDO('mysql:host=mysql;dbname=mydb;charset=utf8mb4', 'myuser', 'mypassword');
} catch (PDOException $e) {
$output = 'Unable to connect to the database server: ' . $e->getMessage();
}
After connection script I need to rewrite my old script using obsolete mysqli_query (), mysqli_num_rows() and mysqli_fetch_assoc () in PDO format; also based on url, and I don't know how to do it.
<?php
$url = isset( $_SERVER[ 'REQUEST_URI' ] ) ? basename( $_SERVER[ 'REQUEST_URI' ] ) : false;
$querysl="SELECT * from metatags where page_url='$url'";
$queryres=mysqli_query($myConnection,$querysl);
$pagerow=mysqli_num_rows($queryres);
$pagedata=mysqli_fetch_assoc($queryres);
And of course display on the page.
<?php echo $page_title; ?>