Creating a new table in MySql

wxdqz

New Member
Hey all,

I'm pretty new to PHP but have heard a lot of commentary on how well it interacts with MySql, so here goes:

I am trying to set-up a database for a local car dealership. From what I understand of MySql documentation the fields will be as follows:

Year - smallint
Make - varchar
Model - varchar
Color - varchar
Mileage - mediumint
Price - mediumint

I am not running the web site on my own server, it is being hosted by pair.com. The database is created and named, but that is all Pair.com lets you do over the web. Still with me? Here's where I am stuck:

Pair.com suggests using PHP to "access your MySql database via the web" and provides some source to help as follows:

<?php

// Connect To Database
// * mysql_connect takes the servername, user, and password
// * as arguments. mysql_selectdb takes the database name.
// * Together, they open a connection to your database.
mysql_connect($SERVER,$USER,$PASSWORD);
mysql_selectdb($DATABASE);

// Execute Query
// * mysql_query takes as its argument the query you are
// * executing on the database. It should be assigned to
// * a variable -- the variable is used by other functions
// * to retrieve the results.
$QUERY = mysql_query("SELECT * from test");

// How man rows in results?
// * mysql_num_rows takes the variable the query was
// * assigned to (referred to hereafter as the query
// * identifier) and returns the number of rows the query
// * resulted in.
$NUMROWS = mysql_num_rows($QUERY);

// Display Results
if ($NUMROWS) {
$I = 0;
while ($I < $NUMROWS) {
// Get Results
// * mysql_result returns the value of a specific field
// * in a specific row. It takes three arguments: the
// * first is the query identifier, the second is the row
// * number, and the third is the field name. In this
// * example, a while loop is used to process all
// * rows.
$FIELD1 = mysql_result($QUERY,$I,"field1");
$FIELD2 = mysql_result($QUERY,$I,"field2");
$FIELD3 = mysql_result($QUERY,$I,"field3");
echo "field1 = $FIELD1, field2 = $FIELD2, field3 = $FIELD3 \n";
$I++;
}
}

?>


Now, to me it looks like this source is geared towards a database that already has it's tables set up. What I would like to do is use php to set up the table itself if it is possible?

Thanks for reading all of this and any help is much appreciated. Also, please keep in mind that I am very new to both PHP and MySql.

Dan
 
Back
Top