Categories

Thursday, March 28, 2024
#919814419350 therichposts@gmail.com
MysqlPDOPhp

Use StdClass Object In PDO

Use StdClass Object In PDO

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

therichpost
the authortherichpost
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 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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