The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
How to set a variable for a cached template in a custom page?
I'm trying to use data from MYSQL to cache a template.
I know everything with the MYSQL database connection works fine, but I can't seem to get the syntax right for placing the variable within the globaltemplates array. What I'm working with: Code:
// pre-cache templates used by all actions $globaltemplates = array('cruisecams_ports', 'cruisecams_ports_menu', 'adblock_cruisecams_sidebar', 'sociallinks'); I'm trying to replace 'cruisecams_ports' with the data from MYSQL stored in $portcamtemplate. Currently I'm just getting this error "Fatal error: Call to undefined method dbPDO::query_first_slave()" anytime I try and place the variable in the array. All other MYSQL data works fine in the rendered page it's just when I try to set a variable in the template array that the issue occurs. |
#2
|
||||
|
||||
What does the code look like that you are running the query?
|
#3
|
||||
|
||||
Code:
// Get parameters from url query string $db = new dbPDO(); $cruiseportcam_id = !empty($_GET['id'])?intval($_GET['id']):1; // get all the values form your table limited to the first matching row (there should only be one) $query = "SELECT * FROM cruiseportcams WHERE cruiseportcam_id = $portcamid"; // the prepare and bind methods prevent any sort of SQL injection $stmt = $db->prepare($query); $stmt->bindValue("$portcamid",$cruiseportcam_id); $stmt->execute(); // we are only expecting 1 row here... $portcam = $stmt->fetch(PDO::FETCH_ASSOC); // now $portcam is an array of the values from your database $portcamtemplate = $portcam['cruiseportcam_template']; |
#4
|
|||
|
|||
I don't know what dbPDO is, but you probably need to include files to define it.
|
#5
|
||||
|
||||
Quote:
http://net.tutsplus.com/tutorials/ph...tabase-access/ http://net.tutsplus.com/tutorials/ph...-it-correctly/ PDO is a newer and more secure way for PHP to access databases. It is working fine pulling db data I just want to place a template name from the database into the cached templates array but I'm not sure how to write the correct reference to it in PHP to make it work. I've tried options like: 1) $portcamtemplate 2) $portcam['cruiseportcam_template'] 3) echo $portcamtemplate ..and about a dozen other variations |
#6
|
|||
|
|||
Oh, yeah OK. For some reason I was thinking your error said "Call to undefined method dbPDO" but I guess I spaced out and only read part of it.
Maybe the array keys are numbers and you could use the number of the column with the template name, like $portcam[3]. (I assume the column name is 'cruiseportcam_template' and you tried $portcam['cruiseportcam_template'] already). But I'm not sure if what you're doing makes sense. I think the only thing caching templates does is save a database read for each one by getting them all at the beginning, so if you have to do a read just to get the template name you wouldn't save anything. |
#7
|
||||
|
||||
Quote:
Interesting though that actually both $portcamtemplate and $portcam['cruiseportcam_template'] work just fine when referring to it when it needs to be rendered but for some reason both cause that error when trying to cache the template. Thanks. |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|