Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to insert Object in a database?

Tags:

object

php

mysql

Is it possible to insert Object in a database? (Asked in PHP interview.)

like image 528
OM The Eternity Avatar asked May 13 '10 12:05

OM The Eternity


People also ask

Can you store objects in a SQL database?

SQL Server allows you to store serialized objects in JSON or XML format, and then run first-class SQL queries on them.

Can we store object in MySQL database?

You can use the JSON data type of MySQL. You can use the JSON_EXTRACT to get some info from the field and filter it in the WHERE clause. Here is how to use it: JSON_EXTRACT([field], [expression])) , [expression] being how you going to extract the info from the field. Save this answer.

What is database object in MySQL?

A database object is any defined object in a database that is used to store or reference data. Anything which we make from create command is known as Database Object.It can be used to hold and manipulate the data.


2 Answers

Yes, it is possible, using serialize().

But the answer hugely depends on context.

like image 176
Your Common Sense Avatar answered Sep 23 '22 02:09

Your Common Sense


nobody suggested OR-mappers? interesting …

if you create your database tables so that they represent objects, you can use an object-relational mapper to store the values of your object members to the database.

for php there exists propel and many others

like image 34
knittl Avatar answered Sep 26 '22 02:09

knittl