Hello, I must have over slept as I just noticed that switching to a new host with Php 8.1 started a nightmare.
From some of the reading that I have been doing, I created the following function to connect to my database. This part actually works.
function db_connect() {
// PDO is the acronym of PHP Data Objects
global $link;
// Create a connection to the database using PDO MySQLi
$db_server = 'localhost';
$db_user = '';
$db_pass = '';
$db_name = '';
$charset = 'utf8';
$options = [
PDO::ATTR_EMULATE_PREPARES => true,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_CASE => PDO::CASE_NATURAL
];
try {
$link = new PDO("mysql:host=$db_server;dbname=$db_name;charset=$charset", $db_user, $db_pass, $options);
echo "Connected successfully"."<br>";
} catch(PDOException $e) {
echo "Connection failed: ".$e->getMessage()."<br>";
}
}
Although I tried to change the following code, I keep seeing errors and though it best to ask what is really needed to make this code PDO compatible:
$result3 = mysqli_query($link,"select *, count($table_name_2.cid) as number_photos
from $table_name_2
left join $table_name_1 on ($table_name_2.cid = $table_name_1.catid)
where $table_name_1.catid != 0 and $table_name_2.published != 0
group by $table_name_2.cid
order by $table_name_2.ordering ASC")
or die('Query failed: ' . mysqli_error($link) );
$id=0; $catid = 0;
$CatalogPhotoCount = array();
while($row3 = mysqli_fetch_array($result3)) {
$id++;
$catid = $row3['cid'];
// create new array and populate
$CatalogPhotoCount[] = array('category' => $catid, 'number_photos' => $row3['number_photos'] );
//echo "# ".$id."- category ".$row3['cid']." has ". $row3['number_photos']." photos " ."<br>";
}
$numofqueries2 = mysqli_query($link,"select count(*) as count from $table_name_2");
$rowcnt2 = mysqli_fetch_array($numofqueries2);
echo 'Total number of categories: '.$rowcnt2["count"]; echo "<br>";
mysqli_free_result($result3);
mysqli_close($link);
I look forward to your answers so that I can change the rest of my code.
Thanks in advance.