Friday, July 19, 2024

Use StdClass Object In PDO

Use StdClass Object In PDO

Hello to all, welcome to 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”);
$users = $QUERY->fetch(PDO::FETCH_OBJ);
$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.

the authortherichpost
Hello to all. Welcome to 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.