Saturday, July 11, 2020
therichposts@gmail.com
MysqlPDOPhp

Use StdClass Object In PDO

Use StdClass Object In PDO

Views

Hello to all, welcome to therichpost.com. In this post, I will tell you, How to Use StdClass Object In PDO? PDO means PHP Data Object. PDO is more secure and it is opps based. In this post, I will use php StdClass in pdo query with creating custom StdClass properties.

stdClass is PHP feature.
With stdClass we can create a new object with it’s own properties.

If we do not get any value in our query then we can create or we can assign our own data to that query results with stdClass.
Here is the example code for Use StdClass Object In PDO:

$QUERY = $DBH->prepare(“SELECT * FROM users”);
$QUERY->execute();
$users = $QUERY->fetch(PDO::FETCH_OBJ);
if(empty($users)){
$users = new stdClass();
// assign custom values with stdClass object
$users->id= “0”;
$users->name= “No Name”;
}

There are so many tricky code in PDO and StdClass and I will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.