Expanding on database fields


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 ?

Who is Participating?

Improve company productivity with a Business Account.Sign Up

merwetta1Connect With a Mentor Commented:
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'] = 'whatever.com';
$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
MirageSFAuthor Commented:
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.

Diablo84Connect With a Mentor Commented:
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.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.
MirageSFAuthor Commented:

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.
no problem :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.