Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
  #1  
Old 09-14-2013, 07:04 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 09-14-2013, 08:45 PM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What does the code look like that you are running the query?
Reply With Quote
  #3  
Old 09-14-2013, 08:55 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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'];
Reply With Quote
  #4  
Old 09-14-2013, 10:20 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know what dbPDO is, but you probably need to include files to define it.
Reply With Quote
  #5  
Old 09-14-2013, 11:29 PM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
I don't know what dbPDO is, but you probably need to include files to define it.

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
Reply With Quote
  #6  
Old 09-15-2013, 01:46 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 09-15-2013, 02:42 AM
bzcomputers's Avatar
bzcomputers bzcomputers is offline
 
Join Date: Apr 2012
Location: TX
Posts: 503
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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.
You're right, I guess I'll just skip the caching of it. Not really much being saved anyway.


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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:35 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04100 seconds
  • Memory Usage 2,219KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete