PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Aug 21, 2017 2:42 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Nov 15, 2016 5:17 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 325
In my records.twig file i have this variable record ... which has a property views , now views is of integer type in the database , With a default value of 0 , Now everytime the record.twig template is loaded , i want to update the value of the views property in the database. How do i do this in bolt ?? So the update statement will be something like:

Update the views property ... where the ID is equal to the current record ID.

Now ofcouse i can do some hardcording like the following:

Syntax: [ Download ] [ Hide ]
   $db = new PDO('mysql:host=localhost;dbname=peckinga_tinyblog', 'peckinga_general', 'gautam');  
   // Update views
   $query = "UPDATE tinyblog SET views = views + 1 WHERE id = :views_id";
   $stmt = $db->prepare($query);
   $stmt->execute(array(":views_id"=>$article_id));


But is there a bolt specific way of doing this or a more efficient way ??


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 5:25 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6268
Location: Montreal, Canada
Start here: https://docs.bolt.cm/3.2/internals/cont ... ces#app-db

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Nov 15, 2016 6:06 pm 
Offline
Forum Contributor
User avatar

Joined: Wed May 14, 2014 12:18 pm
Posts: 325
Celauran ! Awesome .. thanks aloot :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group