Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
System that counts the data in the table in the database ( I wrote it from Translator ) [PDO]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Novaytre" data-source="post: 462708" data-attributes="member: 86483"><p><span style="font-size: 15px">Hi friends. I wanted to open a help topic for friends who research PDO.</span></p><p><u><span style="font-size: 15px">In this context, we find the number of data of the table in the database using PDO.</span></u></p><p></p><p></p><p><strong>Let's connect the database first.</strong></p><p>[CODE=php]try {</p><p></p><p> $db = new PDO('mysql:host=localhost;dbname=DBNAME','root','');</p><p></p><p>} catch (PDOException $e) {</p><p></p><p> echo $e->getMessage();</p><p>}[/CODE]</p><p></p><p><strong>Here we have selected a table and we want to know how many data we select in this table.</strong></p><p>[CODE=php]$userscount = $db->prepare('SELECT COUNT(*) FROM users');[/CODE]</p><p></p><p><strong>I leave it blank because I will not enter an ID value or want any information.</strong></p><p>[CODE=php] $userscount->execute();[/CODE]</p><p></p><p><strong>Finally we will use it now. fetchColumn(); We want to shoot them all using the codes as follows;</strong></p><p>[CODE=php]$alluserscount = $userscount->fetchColumn();[/CODE]</p><p></p><p><strong>Now we have entered our php query and we want to know the number of users immediately. So let's suppress our value with echo.</strong></p><p>[CODE=php]echo $alluserscount[/CODE]</p></blockquote><p></p>
[QUOTE="Novaytre, post: 462708, member: 86483"] [SIZE=4]Hi friends. I wanted to open a help topic for friends who research PDO.[/SIZE] [U][SIZE=4]In this context, we find the number of data of the table in the database using PDO.[/SIZE][/U] [B]Let's connect the database first.[/B] [CODE=php]try { $db = new PDO('mysql:host=localhost;dbname=DBNAME','root',''); } catch (PDOException $e) { echo $e->getMessage(); }[/CODE] [B]Here we have selected a table and we want to know how many data we select in this table.[/B] [CODE=php]$userscount = $db->prepare('SELECT COUNT(*) FROM users');[/CODE] [B]I leave it blank because I will not enter an ID value or want any information.[/B] [CODE=php] $userscount->execute();[/CODE] [B]Finally we will use it now. fetchColumn(); We want to shoot them all using the codes as follows;[/B] [CODE=php]$alluserscount = $userscount->fetchColumn();[/CODE] [B]Now we have entered our php query and we want to know the number of users immediately. So let's suppress our value with echo.[/B] [CODE=php]echo $alluserscount[/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
System that counts the data in the table in the database ( I wrote it from Translator ) [PDO]
Top