Help - Search - Members - Calendar
Full Version: By which specific command does PDO queries a database. Apart from $db ?
HTMLHelp Forums > Programming > Databases
xcislav
$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.
xcislav
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 is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.