Home Mysql Use StdClass Object In PDO

Use StdClass Object In PDO

by therichpost
0 comment
Php Preg_Match Pattern for Week Days Name

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”);
$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. Therichpost.com

You may also like

Leave a Comment

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