Solved

Expanding on database fields

Posted on 2004-09-16
6
160 Views
Last Modified: 2008-03-06
Hi,

I have a database that contains,

Client ID
Username
Password
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 ?

Cheers
0
Comment
Question by:MirageSF
  • 2
  • 2
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
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'] = '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
0
 

Author Comment

by:MirageSF
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.

Cheers
0
 
LVL 27

Assisted Solution

by:Diablo84
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
Username
Password

etc

Then the second table may look like this:

Client ID
Domain Name
Date

etc

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.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:merwetta1
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.
0
 

Author Comment

by:MirageSF
ID: 12133884
Hi,

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.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12133914
no problem :)

|)iablo
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now