Expanding on database fields

Posted on 2004-09-16
Last Modified: 2008-03-06

I have a database that contains,

Client ID
Domains etc...

But also want the Domains field to hold, Domain Name, Username, Password, Date etc, is it possible to do this and how ? or do I have to create another table and reference this ?

Question by:MirageSF
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2

Accepted Solution

merwetta1 earned 75 total points
ID: 12081598
I think what you're asking is how to store a wide variety of domain info in one field. if that's not true, please clarify.

I suggest using serialize and unserialize to store a variety of info. You put the info into an array, serialize it, and then store it in the database. When you pull it out of the database, you unserialize it and you have your array back.

for example:

$domain_info['domain_name'] = '';
$domain_info['registrar'] = 'network solutions';
$domain_info['username'] = 'user';
$domain_info['password'] = 'pass';
$domain_info['expiration'] = '9/25/04';
## add whatever else you want

$domain_info_serialized = addslashes(serialize($domain_info));
## routine to store $domain_info_serialized in domain field goes here

Then when you want the info back, after you retrieve it from the database, just use something like:

$domain_info = stripslashes(unserialize($data_from_db));
echo "domain: ".$domain_info['domain_name']."<br>";
echo "registrar: ".$domain_info['registrar']."<br>";
echo "username: ".$domain_info['username']."<br>";
echo "password: ".$domain_info['password']."<br>";
## etc.

hope that helps

Author Comment

ID: 12081619
Hi Thankyou thats pretty much correct, but that would allow me to add alot of data to the domain field for example, but what if I want to add another domain to that user, again seralise it and reference it how ?

So some users may have 1 domain in there data, whereas others may have 2 or more, each needs to be stored and referenced.

LVL 27

Assisted Solution

Diablo84 earned 50 total points
ID: 12082297
I think it would be better to have a second table and cross reference them.

for example your first table would resemble:

Client ID


Then the second table may look like this:

Client ID
Domain Name


Then your queries can just reference the Client ID to retreive matching information from both tables, hypothetical example:

SELECT * FROM first_table WHERE username='$username' AND password='$password'

you can then use the ID returned from that query to get a list of the domains owned by that user in the second table

SELECT * FROM second_table WHERE Client ID='$clientid'

This means you can have multiple domains owned by one user in induvidual rows in the second table without causing any inconvienience.
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.


Expert Comment

ID: 12087089
the question asked if it was possible, so i gave a solution. but, cross referencing a domain table is by far the best solution. use the serialize trick if you need to store diverse information, and use another table if you need to store repetitive info.

Author Comment

ID: 12133884

I decided to split the points 75 - 50, as merwetta1 answer was correct to my question, however Diablo84 I decided to go your root as its more of a practical and easier managed solutions.

Thanks to both of you.
LVL 27

Expert Comment

ID: 12133914
no problem :)


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question