Page 1 of 1

I Need Help With Php/Database

Posted: Sat Dec 17, 2005 7:23 pm
by word32
ok, so i'm a little new to PHP, but i took some classes on databases, and now i'm good with that, using exel and microsoft works. but anyway, heres my problem

i have been looking for a way to make a radio for months now, but i never found one so, "cost efficient". so then i had an idea, i could make a radio with php. i could make a database with all the songs, there names, artists, and length of song. i could have a flash receiver to interpret the data (i have the flash part handeled)

i just need to know how to make the database. can i give the web access to my works database? i have a very good server online. and i need something like a text box that can search through the database for a certain song you type in, and then you click a button and the data is sent to my flash receiver.

thx for reading the long message and thx in advance,
-word32

Posted: Sat Dec 17, 2005 9:28 pm
by BDKR
Focusing on just the database, I'm not sure if it's possible to get PHP and MS Works to play nice together. Most things written in PHP involving a database use something a bit more robust then Works or Access. MySQL is a big favorite in this community. Others include MS SQL, Postgres, Sybase and Oracle.

My suggestion at this stage would be to
1) Learn about database practices and web development with PHP
2) The figure out if MS Works is still a viable solution to your problem.

My suspicion is that you'll find it a lot easier to move to something like MySQL instead of continuing to focus on Works.

Now to focus on the app itselt, I do agree that a database can be a good candidate to store this kind of info. Another option if you don't have access to a database or decide not to use one would be a tree like data structure that can be serialized and stored to file when the app closes. An example would be like below.

Code: Select all

<?php
$artists=array
    (
    'artist_name'=>array
    	(
	'album'=>array
		(
		'Title'=>'',
		'Info'=>'',
		'Number_of_songs'=>'',		
		'songs'=>array
		 	(
		 	'song_title'=>array
		 		(
				'length'=>0,
				'path'=>''
				),		 
		 	),
		),
		
	'single_or_ep'=>array
		(
		'Title'=>'',
		'Info'=>'',
		'Number_of_songs'=>'',		
		'songs'=>array
		 	(
		 	'song_title'=>array
				(
				'length'=>0,
				'path'=>''
				),
		 	),
		),
	),
    );
    
  print_r($artists);
?>
However, I don't really suggest this. A DB is a great 1st choice and relational DB's are designed to overcome the headaches surrounding the kind of storage scenarios in the code example above.

Cheers,
BDKR

Posted: Sun Dec 18, 2005 2:22 pm
by word32
ok, but mi server doesnt let me make databases, it only stores them

Posted: Sun Dec 18, 2005 5:30 pm
by method_man
dont you have phpmyadmin?

Posted: Sun Dec 18, 2005 5:56 pm
by word32
yes, but it only says:


Databases:
habbotim_Songs Check Repair Delete

Users in Songs
habbotim_cop1 (Privileges: ALL PRIVILEGES)

Connection Strings
Perl $dbh = DBI->connect("DBI:mysql:habbotim_Songs:localhost","habbotim_cop1","<PASSWORD HERE>");
PHP $dbh=mysql_connect ("localhost", "habbotim_cop1", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("habbotim_Songs");

it wont let me make new feilds, it only checks or reppairs (i dont know wat either of them do!)

-word

Posted: Sun Dec 18, 2005 6:02 pm
by Smackie
you might want to look down more on that page you might see a link to the phpmyadmin

Posted: Mon Dec 19, 2005 5:29 pm
by word32
lol, whoops it was there the hole time

wow, this is way different than works. what does VARCHAR and all the others mean? and theres only feilds, not orginized into records

help,
-word

Posted: Mon Dec 19, 2005 5:34 pm
by hawleyjr
word32 wrote: what does VARCHAR and all the others mean?
-word
http://kimbriggs.com/computers/computer ... types.html

Posted: Tue Dec 20, 2005 4:28 pm
by word32
ok, so i just made one feild, i made it text. i dot really get this, it says:

|Field| TypeDocumentation| Length/Values* |Attributes| Null |Default**| Extra|

and then it has all the boxes under each of thoes to fill out. what the heck? what are all these?

help,
-word

Posted: Tue Dec 20, 2005 6:09 pm
by trukfixer
Hmm
sounds like you need a good reference-

Varchar is basically a string of mix characters (numbers, symbols, alphabet, whatever) with a maximum length of 255 characters in length ..

but to help you further, I'd recommend bookmarking the MySQL manual, and reading the second link which explains all the column types ..

http://dev.mysql.com/doc/refman/4.1/en/


http://dev.mysql.com/doc/refman/4.1/en/ ... types.html

and for a quick tutorial :

CREATE TABLE my_table (
id bigint(20) unsigned not null auto_increment,
first_name varchar(65) not null default 'anonymous',
last_name varchar(65) default NULL,
login_stamp datetime default '0000-00-00 00:00:00',
PRIMARY KEY id (id),
UNIQUE no_dup(first_name,last_name)) type=MYISAM;

now lets take it apart line by line -
id is always numeric when auto incremented (each row gets a unique number automatically when inserted)
id being a bigint(20) means it can have a long integer value up to 20 places , the "unsigned" means that it will *never* be a negative value .. A side note- a bigint(20) unsigned can actually only go to 18 digits (it's an exponent of 32) 18E+18 - I cant give the exact number from memory, but 18 quintillion rows , well.. it's way more than any database might realisically have - unless you are running a Cray supercomputer , I dont think you'd get much beyond 15 million rows of data, unless you are an absolute expert at optimizing your mysql tables :)

next up - last_name is a varchar (variety of characters) which can take numbers, text, symbols, etc, however these are limited to (I think) not more than 255 characters in length - for larger data, use text type the number in parentheses(65) is nominally the length of the string that can be inserted (in this case, 65 characters). and if no value is given during the insert, it will default to NULL (in octal, \0 ) - basically an empty field, that when you grab the data , you will *visually* see the keyword "NULL" but the actual data is just \0 or "" , while first_name is being set as NOT NULL - which means an empty insert will result in the default value being entered, and if none is given it's blank, and in the case of the above, an empty value for that column results in a default of 'anonymous' being inserted in that row. - the login is a date stamp in the ISO format (guys correct me if Im wrong, Im not sure if it is called the ISO format, but I know it is an international standard)

the Primary key is id (auto_increment will typically be the primary key, and it will always be unique)

and finally - the UNIQUE index assures that no duplicate of those two columns will exist in the database ..

its just a general example - I just wrote it up off the top of my head, I cant guarantee that just dumping that create table query will work - actually I think it will probably give an error.. but you get the general idea :)

Posted: Tue Dec 20, 2005 8:47 pm
by word32
wow, thank you that really helps