Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,843 members, 7,810,250 topics. Date: Saturday, 27 April 2024 at 02:27 AM

Pdo::fetch_class Vs. Pdo::fetch_props_late - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Pdo::fetch_class Vs. Pdo::fetch_props_late (825 Views)

PDO::FETCH_CLASS Example / Login And Regisatration In Php Using PDO / PHP Mysql Connection Using PDO (2) (3) (4)

(1) (Reply)

Pdo::fetch_class Vs. Pdo::fetch_props_late by skptricks: 6:55am On Oct 31, 2017

Complete details Link
: http://www.skptricks.com/2017/10/pdofetchclass-vs-pdofetchpropslate.html

PDO::FETCH_CLASS

In our last post we have discussed about PDO::FETCH_CLASS, from which I think you are able to build complete understanding on PDO::FETCH_CLASS. But in this we are going to discuss about few shortcomes about PDO::FETCH_CLASS.

Lets see the below example for PDO::FETCH_CLASS.

<?php
// < Class : user >
// class consists of userdefine functions and variables
class user{

private $USERNAME ;
private $EMAILID ;
private $AGE ;
private $COUNTRY ;
//get the username
public function getUSERNAME(){
return $this->USERNAME ;
}
//get the email id
public function getEMAILID(){
return $this->EMAILID ;
}
//get the age
public function getAGE(){
return $this->AGE ;
}
//get the country
public function getCOUNTRY(){
return $this->COUNTRY ;
}
public function __construct(){
$this->USERNAME = "sumit@gmail.com";

}

}

// < Class : DAO >
// Get the data from database...
Class DAO{

//function return the all the data from database...
public function getAllUserDetails(){

$dbhost ="localhost"; // set the hostname
$dbname ="skptricksdemo" ; // set the database name
$dbuser ="root" ; // set the mysql username
$dbpass =""; // set the mysql password

try {
$dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbConnection->exec("set names utf8"wink;
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully.<br>";

$stmt = $dbConnection->prepare('SELECT * FROM `userdetails` WHERE `AGE` > 10 ');
$stmt->execute();

$Count = $stmt->rowCount();
echo " Total Records Count : $Count .<br>" ;

if ($Count > 0){
$stmt->setFetchMode(PDO::FETCH_CLASS, "user"wink;

return $obj = $stmt->fetchAll();

}

}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}

}
}


// calling the getAllUserDetails function and retrieve details
$dao = new DAO();
$allUserDetails =$dao->getAllUserDetails();

//echo print_r($allUserDetails);
foreach($allUserDetails as $user)
{
//echo print_r ($UneNews);
echo "<pre>".$user->getUSERNAME()."</pre>" ;
//echo "<pre>".$user->getEMAILID()."</pre>" ;


}

?>


OUTPUT:
-------------------------------
Connected successfully.
Total Records Count : 4 .
sumit@gmail.com
sumit@gmail.com
sumit@gmail.com
sumit@gmail.com

(1) (Reply)

Convert URL To Clickable Link Using PHP / Self Development Needs / Create Circle Loader Animation Using CSS3

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 10
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.