After reading the post about migrating my MySql deing depreciated I decided to change my code over to use pdo. After a bit of a fight I managed to get the first page sorted although it seems a bit of a waste that every query is connecting to the database when the previous query has already opened it.

But my second page is more of a problem as I am using a user function with the database query inside it.
I have tried putting the database connection details with the function like this:
PHP Code:
Function gallery$gallery_name$host$user$pass$dbname ){
$DBH = new PDO("mysql:host=$host; dbname=$dbname"$user$pass);
$STH $DBH->query("SELECT * FROM plans.........");
// etc.
 
}
gallery$gallery_name‘localhost’‘username’‘password’‘database’ ); 
I have also tried:
PHP Code:
$DBH = new PDO("mysql:host=$host; dbname=$dbname"$user$pass);
Function 
gallery$gallery_name$DBH){
$STH $DBH->query("SELECT * FROM plans.........");
//etc.
 
}
gallery$gallery_name$DBH); 
Neither of these has worked; what is the best way to do this?