...

View Full Version : php and mySQL functions.....



c q
09-14-2002, 07:20 PM
heyy !!!
I ws wondering how to create a mySQL database that has a table with say 5 fields. Out of which some fields themselves contain another table. I sort of looked thru the manual, but I'm still confused.

Spookster
09-14-2002, 08:00 PM
This belongs in the MySQL forum as mentioned in the Must Read thread at the top of this forum. I'll move it there....

c q
09-14-2002, 08:05 PM
uhh ohh I think I forgot to add.....I'd llike to be using php to do this...:D

Spookster
09-14-2002, 09:34 PM
You can't create database and tables with PHP. SQL is what is used to create it. PHP just makes the connection to MySQL and sends the commnads to MySQL.

Easiest way to do this is once again to use phpMyAdmin. It's a graphical tool so no need to learn SQL to create the database or tables.

c q
09-15-2002, 07:08 AM
arre....this is news to me.
coz when I ws installing mySQL on my system, I followed a tutorial tht gave me this code....

<h3> Press RELOAD to add a record to the MySQL database:</h3>
<?
//establish user connection
mysql_connect("localhost");
//open up database
mysql_create_db("testdatabase");
mysql_select_db("testdatabase");
//create table
mysql_query("CREATE TABLE newone(firstName VARCHAR(25),lastName VARCHAR(25))");
mysql_query ("INSERT INTO newone (firstName, lastName) VALUES ('Amir', 'Khan')");
//display the information
$result = mysql_query ("SELECT * FROM newone");
while($row = mysql_fetch_array($result))
{
print ("Added record: " . $row["firstName"]." ".$row["lastName"]." <br>\n");
}
//close user connection
mysql_close();
?>

now that sort of made me believe that php can as well create a table.
ok anyhow methinks that phpmyAdmin is much simpler and lot quicker :D

Spookster
09-15-2002, 08:57 AM
PHP doesn't create tables. All PHP does is send a command to MySQl whom which then creates the tables. So all PHP is doing is passing messages.

c q
09-16-2002, 05:31 PM
okie....getting my phpmyadmin right now....the link aparently is www.phpmyadmin.net :D
thanx for the help ...;)

c q
09-17-2002, 06:24 PM
awwp :o

hmm....again that myadmin is not really helping me...
made a nice database alright, and a table with 3 pretty fields.
I cant make out how I can create a "field" which contains an array. Is it possible in the first place ?
wht i really need is a field that'll store a list of items I will access later. so if I have ten entries in the table, each of those ten entries will have a list corresponding to them....dunno how to proceed.

Dylan Leblanc
09-18-2002, 12:30 AM
It depends on how you want to use your data.

You could have a field which stores contents such as "6,2,9,2,4,7" which could be an array, but it depends on if that will work for you or now.

Or, make another new table for your array, and link the two tables with ID numbers. Are you familiar with database normalization and joining tables?

c q
09-18-2002, 08:38 AM
Well....I only recently started reading up on databases.
I'm trying to build me own little CBT; roughly sketched, I can say here's wht the fields look like...
id | word | meaning | synonyms | antonyms
the last 2 fields synonyms and antonyms need to be arrays.
becoz when compiling my questions, I will randomly select any antonym corresoinding to the already selected word.
that about summarises my plan :D

Dylan Leblanc
09-18-2002, 08:54 AM
ok, well then in the database, separate multiple words (the synonyms and antonyms) with commas in their DB field.

Then read the values out of the database and into a variable, so the long string of synonyms get put into a variable $synonyms lets just say.

Then, if you are using PHP, you can turn the comma separated words in the $synonyms variable into an array of words by using the explode() function. Look it up at php.net

c q
09-18-2002, 09:00 AM
boss something just struck me real hard...
what if I create an object that stores these arrays...
and enter this object in my field ?
just a weird idea...but somehow it strikes as the only way to do it. what say ?
but I need help with the coding again !!

Dylan Leblanc
09-18-2002, 09:46 AM
you might be able to do it that way. how do you store objects in the DB?

c q
09-18-2002, 04:42 PM
Originally posted by Dylan Leblanc
ok, well then in the database, separate multiple words (the synonyms and antonyms) with commas in their DB field.

Then read the values out of the database and into a variable, so the long string of synonyms get put into a variable $synonyms lets just say.

Then, if you are using PHP, you can turn the comma separated words in the $synonyms variable into an array of words by using the explode() function. Look it up at php.net


ths simply a kewl idea...much simpler I must say. thanx buddy u solved my biiiiiiig problem !


by the ways....Re: how do you store objects in the DB?
emm....I heard that storing data as 'blob' is used for this purpose.
neways, methinks your idea is nicer, I'll sort of work on it...thanks again. :thumbsup:

mordred
09-19-2002, 01:49 AM
Check out the serialize() and unserialize() php functions to make a string representation of an object and store that in your table, of course in an appropriate field of some text type (text, mediumtext, even blob if you like consume as much space as possible).

And I can only second Dylan Leblancs suggestions: Reconsider your approach to a relational database. Perhaps a different database design could server your needs in a more efficient and straightforward way. Alternativley, there are also object oriented databases, though I can't provide you much info about them.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum