The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> By which specific command does PDO queries a database. Apart from $db ?, Solely, specifically about $db issue. An explanation added (towar
xcislav
post Apr 8 2014, 04:55 PM
Post #1


Newbie
*

Group: Members
Posts: 12
Joined: 1-April 14
Member No.: 20,652



$db is a variable and from (instruction/command/operator) perspective it's dead and non-wonking.

All documentation which I googled is vague. It does not say explicitly:
Solely set $db makes an sql query.

For example I have one working code which greps a table from my DB:

CODE
<?php $db=new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', 'hyuiuik'); foreach($db->query('SELECT * FROM TABBL') as $value) { echo $value['nn']; }


foreach seems to be this instruction.

I'm doing all this to build a voting system with like button (in js/php(pdo)/mysql(txt) - minimal implementation.
This plus one ("+1") "like button"-voting system which i want to have the maximum minimalist approach (no auth non-voting non-login). Just 1. Press - HTML/Javascript
<input type="button" id="like" onClick="like1()" value="+1">
<script>
function like1 {
like.value += 1
}
</script>
2. Send PHP (PDO!) 3. Receive Textfile (may be.. mysql) *it has to be as simple as it could be* 4. Show +1, which would be visible to other visitors (ajax/js - optional). That example to be working. I have mysql and apache and php PDO (php5.5.6)! (I've googled this http://lanother.tk/likebutton.html - complex)


And if I solve this PDO issue - it will be very important.

This post has been edited by xcislav: Apr 8 2014, 05:18 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
xcislav
post Apr 15 2014, 06:26 AM
Post #2


Newbie
*

Group: Members
Posts: 12
Joined: 1-April 14
Member No.: 20,652



Post is self-answered.

CODE
<?php $db=new PDO('mysql:host=localhost;dbname=test;charset=utf8','$us','$ps');$db->exec("UPDATE TXT SET cn=cn+1");$rs=$db->query("SELECT cn FROM TXT");print_r($rs->fetchColumn());?>


The answer is: PDO queries a database of SQL/SELECT by $db->query
via an object-assignment procedure. $rs=
So print_r($rs->fetchColumn()) finally retrieves THE SELECTION as a minimal possible approach.
fetchColumn in this case is more specific (and focused) than the whole set (the set is retrieved from database as an array).


Close the topic, please.

This post has been edited by xcislav: Apr 15 2014, 06:28 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 16th February 2019 - 04:18 PM