Forum Moderators: coopster

Message Too Old, No Replies

help! simple database question

         

aznbruinboy

4:12 am on Jul 6, 2004 (gmt 0)

10+ Year Member



Hi everyone, I just have a pretty simple quesiton, and i guess it's pretty obvious that i'm new to php so i have no idea where to start.

Basically I'm creating a database that just stores user accounts from the website. I will have to store the information on the server, and i was thinking that an associated array with the usernames as the key would do the trick. but i need the arrays to be stored when the session ends, so how would i save the data as a seperate file? what kind of file format would allow my php program to go back and read the data as an associated array?

I need to be able to go back into the file and alter it when i create more user accounts.

How should I implement this? Thank you so much for the help guys! My question may be a bit confusing, but i guess it's cuz i'm a noob =P Your help is appreciated!

ExpLarry

5:51 am on Jul 6, 2004 (gmt 0)

10+ Year Member



If available I would use a "proper" database such as MySQL. Storing data in filesystem files in a webserver context can be quite tricky - it is possible that several web server processes may be running concurrently (such as when several people access your site at the same time) and each process may be trying to write to the same file, which is not a good idea. It is of course possible to handle this yourself, but a PITA at the same time.

There may be other ready-made solutions for PHP which don't require a database, but I'm not sure.

timster

12:58 pm on Jul 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using a SQL database for this would be a good idea. It might seem like overkill initially, but it's likely you'll grow into in quickly.

If right now all you need is a persistent hash, PHP can do that:

[us4.php.net ]

aznbruinboy

1:48 am on Jul 7, 2004 (gmt 0)

10+ Year Member



Thanks! So I started using mysql now. And i've read the tutorials. however, none of the tutorials say what I should do if i accidentally type in the wrong key when creating a database (e.g. i use a "{" instead of a "(" )

So now, it says

mysql> CREATE TABLE tableName
-> {
-> fieldName CHAR(15)
-> fieldName CHAR(15)
-> fieldName VARCHAR(16)
-> )
-> ;
ERROR 1064: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '{
fieldName CHAR(15)
fieldName CHAR(15)
fieldName VARCHAR(16)
)

in the log. What can i do to change the "{"?

timster

1:45 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, you can have a lot of fun with things like that.

When writing complex queries, you can create them in a text editor (preferably one with SQL syntax coloring) and feed that input into MySQL at the command line like so:

mysql -u username -p < file.sql

-Or, you can paste it into your CLI, if yours allows it.
-Or, you can get a MySQL front end app to make your life easier.

aznbruinboy

12:10 pm on Jul 8, 2004 (gmt 0)

10+ Year Member



i get it, thanks a lot guys!