School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store | FORUMS

Class / Forums / mysql101 Refresh the current page Week #2 Basic To-Do Assignment
 

 (#17 2003-08-15 13:22:44) Post Reply

TDavid
php mySQL Perl C/C++
Principal


Enrolled: Mar 2000
Posts: 193
AP: 1

Your Week #2 Basic TO-DO assignment should be posted here in this thread only. If you have specific questions about the week 2 course text then please also post them in this thread so that other students can learn from the information and we can collectively build a knowledge base.

Here is the details on what you need to do in this assignment:

Construct the Tables as indicated in this week's lesson and post the working source code here. Go back to Week #1 to see how to do this if you have to. Study CREATE TABLE queries in the MySQL manual if neccessary as well.

 

 (#21 2003-08-20 19:03:31) Post Reply

lizabit
Need To Set


Enrolled: Jul 2003
Posts: 17
AP: 1

I saved 3 files, one created the database and the first table. The other 2 files for each of the other tables. I am implementing them on my localhost so there is no link to post.

create the database and add 1 table
<?
//connect to MySQL server:
$db = mysql_connect("localhost", "lgrace", "nicho6uz")
or die("Could not connect:". mysql_error());

//create the database:
$query_create_db = "CREATE DATABASE IF NOT EXISTS MySponsors";

//Implement db
$result_create_db = mysql_query($query_create_db,$db)
or die("Could not create database:". mysql_error());
print("Database Created");

//connect to db
mysql_select_db("MySponsors", $db)
or die("Could not connect to database:". mysql_error());
print("Connected to database");

//create table
$query_create_table = "CREATE TABLE Website_Sponsor (
ws_w_id MEDIUMINT(8) NOT NULL,
ws_s_id MEDIUMINT(8) NOT NULL,
KEY (ws_w_id),
KEY (ws_s_id)
)
TYPE=MyISAM";

//execute table query
$result_create_table =
mysql_query($query_create_table,$db)
or die("Could not create table:". mysql_error());
print("Table Created");
?>

make sponsors table
<?
//connect to MySQL server:
$db = mysql_connect("localhost", "lgrace", "nicho6uz")
or die("Could not connect:". mysql_error());

//connect to db
mysql_select_db("MySponsors", $db)
or die("Could not connect to database:". mysql_error());
print("Connected to database");

//this is a php variable which creates table
$query_create_table = "CREATE TABLE sponsors (
s_id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
s_name VARCHAR(255) NOT NULL DEFAULT '',
s_url VARCHAR(255) NOT NULL DEFAULT '',
s_staturl VARCHAR(255) NOT NULL DEFAULT '',
s_email VARCHAR(255) NOT NULL DEFAULT '',
s_uname VARCHAR(255) NOT NULL DEFAULT '',
s_pass VARCHAR(255) NOT NULL DEFAULT '',
s_date DATE DEFAULT NULL,
S_status ENUM ('Pending','Active','Inactive','Defunct') NOT NULL DEFAULT 'Pending',
PRIMARY KEY (S_id)
)
TYPE=MyISAM";

//execute table query
$result_create_table =
mysql_query($query_create_table,$db)
or die("Could not create table:". mysql_error());
print("Table Created");
?>

and finally make websites table
<?
//connect to MySQL server:
$db = mysql_connect("localhost", "lgrace", "nicho6uz")
or die("Could not connect:". mysql_error());

//connect to db
mysql_select_db("MySponsors", $db)
or die("Could not connect to database:". mysql_error());
print("Connected to database");

//this is a php variable which creates table
$query_create_table = "CREATE TABLE Websites (
w_id MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
w_name VARCHAR(255) NOT NULL DEFAULT '',
w_url VARCHAR(255) NOT NULL DEFAULT '',
w_desc TEXT,
w_status ENUM ('Pending','Active','Inactive','Defunct') NOT NULL DEFAULT 'Pending',
PRIMARY KEY (w_id),
FULLTEXT KEY w_search (w_name, w_url, w_desc)
)
TYPE=MyISAM;";

//execute table query
$result_create_table =
mysql_query($query_create_table,$db)
or die("Could not create table:". mysql_error());
print("Table Created Websites");
?>

OK?
Regards
Liz

 

 (#30 2003-09-02 23:32:22) Post Reply

logspirit
Need To Set


Enrolled: Oct 2001
Posts: 63
AP: 1

Looks OK

logspirit

 

 (#44 2003-09-18 09:52:54) Post Reply

Shrek
Need To Set


Enrolled: Aug 2003
Posts: 33
AP: 1

Here is My Week #2 Assignment

sql02.create.ws.php

<?php
$db
= mysql_connect("localhost","sqlclass", "sqlclass")or die("Could not connect:". mysql_error());
print(
"Connected successfully</br>");

mysql_select_db("ssMySQLclass",$db)
or die(
"Could not Connect to database:". mysql_error());
print(
"Connected to Database</br>");

$query_create_table = "CREATE TABLE `Website_Sponsor` (
`ws_w_id` MEDIUMINT(8) NOT NULL,
`ws_s_id` MEDIUMINT(8) NOT NULL,
KEY (`ws_w_id`),
KEY (`ws_s_id`)
) TYPE=MyISAM;"
;

$result_create_table =
mysql_query($query_create_table,$db)
or die(
"Could not Create Table:". mysql_error());
print(
"Table Created</br>");

?>




sql02.create.website.php
<?
$db
= mysql_connect("localhost","sqlclass", "sqlclass")
or die(
"Could not connect:". mysql_error());
print(
"Connected successfully</br>");
mysql_select_db("ssMySQLclass",$db)
or die(
"Could not Connect to database:". mysql_error());
print(
"Connected to Database</br>");

$query_create_table = "CREATE TABLE `Websites` (
`w_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
`w_name` VARCHAR(255) NOT NULL DEFAULT '',
`w_url` VARCHAR(255) NOT NULL DEFAULT '',
`w_desc` TEXT,
`w_status` ENUM ('Pending','Active','Inactive','Defunct') NOT NULL DEFAULT 'Pending',
PRIMARY KEY (`w_id`),
FULLTEXT KEY `w_search` (`w_name`,`w_url`,`w_desc`)
) TYPE=MyISAM;"
;

$result_create_table =
mysql_query($query_create_table,$db)
or die(
"Could not Create Table:". mysql_error());
print(
"Table Created</br>");

?>



sql02.create.sponsor.php
<?
$db
= mysql_connect("localhost","sqlclass", "sqlclass")
or die(
"Could not connect:". mysql_error());
print(
"Connected successfully</br>");

mysql_select_db("ssMySQLclass",$db)
or die(
"Could not Connect to database:". mysql_error());
print(
"Connected to Database</br>");

$query_create_table = "CREATE TABLE `Sponsors` (
`s_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`s_name` VARCHAR(255) NOT NULL DEFAULT '',
`s_url` VARCHAR(255) NOT NULL DEFAULT '',
`s_staturl` VARCHAR(255) DEFAULT NULL,
`s_email` VARCHAR(255) DEFAULT NULL,
`s_uname` VARCHAR(255) DEFAULT NULL,
`s_pass` VARCHAR(255) DEFAULT NULL,
`s_date` DATE DEFAULT NULL,
`s_status` ENUM('Pending','Active','Inactive','Defunct') NOT NULL DEFAULT 'Pending'
) TYPE=MyISAM;"
;

$result_create_table =
mysql_query($query_create_table,$db)
or die(
"Could not Create Table:". mysql_error());
print(
"Table Created</br>");
?>




 

 (#46 2003-09-23 21:49:34) Post Reply

logspirit
Need To Set


Enrolled: Oct 2001
Posts: 63
AP: 1

Shrek, You're on Your way to developing this program and learning as You go!
logspirit

 

 (#55 2003-10-10 15:32:10) Post Reply

Donnie
Need To Set


Enrolled: Aug 2003
Posts: 41
AP: 1

Here is basic week 2.



<?php
/* Connect to MySQL server */
$db=mysql_connect("localhost", "username", "password")
or die (
"Could not connect:".mysql_error());
print(
"Connected Successfully");

/* Connect to database */
mysql_select_db("ssMySQLclass",$db)
or die(
"Could not connect to database:".mysql_error());
print(
"Connected to Database");

/* Create php vaiable containing Table Creation SQL Query */
$query_create_table = 'CREATE TABLE `Website_Sponsor` ( `ws_w_id` MEDIUMINT(8) NOT NULL, `ws_s_id` MEDIUMINT(8) NOT NULL, PRIMARY KEY (`ws_w_id`, `ws_s_id`) );';

/* Execute Query */
$result_create_table =
mysql_query($query_create_table, $db)
or die (
"Could not create table:".mysql_error());
print(
"Table Created");
?>


<?php

// Refer to week #1 to create a database before implementing this code.

// Connect to Your MySQL server (use YOUR parameters):
$db = mysql_connect("localhost","username", "password")
or die(
"Could not connect:". mysql_error());
print(
"Connected successfully");

// Connect to database:
mysql_select_db("ssMySQLclass",$db)
or die(
"Could not Connect to database:". mysql_error());
print(
"Connected to Database");

// Create php variable containing Table Creation SQL Query:
$query_create_table = 'CREATE TABLE `Websites` (
`w_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT,
`w_name` VARCHAR(255) NOT NULL DEFAULT "",
`w_url` VARCHAR(255) NOT NULL DEFAULT "",
`w_desc` TEXT,
`w_status` ENUM ("Pending","Active","Inactive","Defunct") NOT NULL DEFAULT "Pending",
PRIMARY KEY (`w_id`),
FULLTEXT KEY `w_search` (`w_name`,`w_url`,`w_desc`)
) TYPE=MyISAM;'
;

// Execute Query:
$result_create_table =
mysql_query($query_create_table,$db)
or die(
"Could not Create Table:". mysql_error());
print(
"Table Created");

?>


<?php

// Refer to week #1 to create a database before implementing this code.
// Connect to Your MySQL server (use YOUR parameters):

$db = mysql_connect("localhost","username", "password")
or die(
"Could not connect:". mysql_error());
print(
"Connected successfully");

// Connect to database:
mysql_select_db("ssMySQLclass",$db)
or die(
"Could not Connect to database:". mysql_error());
print(
"Connected to Database");

// Create php variable containing Table Creation SQL Query:
$query_create_table = 'CREATE TABLE `Sponsors` (
`s_id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`s_name` VARCHAR(255) NOT NULL DEFAULT "",
`s_url` VARCHAR(255) NOT NULL DEFAULT "",
`s_staturl` VARCHAR(255) DEFAULT NULL,
`s_email` VARCHAR(255) DEFAULT NULL,
`s_uname` VARCHAR(255) DEFAULT NULL,
`s_pass` VARCHAR(255) DEFAULT NULL,
`s_date` DATE DEFAULT NULL,
`s_status` ENUM("Pending","Active","Inactive","Defunct") NOT NULL DEFAULT "Pending"
) TYPE=MyISAM;'
;

// Execute Query:
$result_create_table =
mysql_query($query_create_table,$db)
or die(
"Could not Create Table:". mysql_error());
print(
"Table Created");
?>




Worked on local host. No host to upload to.

 

 (#58 2003-10-14 20:08:17) Post Reply

logspirit
Need To Set


Enrolled: Oct 2001
Posts: 63
AP: 1

looks OK

logspirit - author of this course

 

 

View Previous Thread
Print this page Print This Page

View Next Thread

School Map:  Home / Enroll $ Student Records; Class  
$ News @ LIVE Tech Radio * Support/FAQ | Store

Advertising | Link To Us | Privacy 
Copyright 2000-2002 Script School Productions / KMR Enterprises 
No part of this website may be reproduced, copied and/or distributed in any medium 
without express written permission