Professional Documents
Culture Documents
Fields
Corvettes table
Equip_id Equip
1 Automatic
2 4-speed
3 5-speed
4 6-speed
5 CD
6 Leather
Equipment table
Vette_id Equip
1 1
1 5
1 6
2 1
2 5
2 6
3 1
3 6
4 2
4 6
Corvettes States
Corvettes_Equipment Equipment
MySQL
SQLite
PostgreSQL
Oracle
Microsoft SQL Server
MySQL is free.
m ysql-u yourlogin -p
ES;
SH O W D ATABAS
USE databasename;
There are number of possibilities for type including: varchar (or char) int,
fl
oat(significant digits, digits after decimal).
After specifying type, you may specify the max length of the variable.
eg. varchar(10)
Syntax:
SELECT [fi
elds here] FRO M [tables here];
Show all records from table "students" where the field called
"name" has the value "Joe".
Show all records from table "people" where the field called
"name" has the value "Joe" AND the phone number "555-
6789".
Show all records from table "students" where the field called
"name" has the value "Joe" OR "Bob".
Syntax:
IN SERT IN TO tablenam e (fi eld1,fi
eld2, ...)
VALU ES ('val1', 'val2', ...);
Example:
IN SERT IN TO students (nam e,sid,gpa,phone)
VALU ES ('Zoidberg',77843211, -4.0,"N /A");
Syntax:
U PD ATE tablenam e SET fi
eldnam e = value
W H ERE condition;
Example:
U PD ATE students SET G PA = '3.8'W H ERE person
= 'Joe';
Syntax:
D ELETE FRO M tablenam e W H ERE
condition;
Example:
D ELETE FRO M students W H ERE
nam e= "Fry";
$hostnam = "laguna.pic.ucla.edu";
e = "yourlogin";
$usernam
e
$passw or = "PW 1234";
Connect
d and login to MySQLserver and store link to it as resource
$databas = "dbyourlogin";
$db
e = m ysq l_con n ect($hostnam e,$usernam e,
$passw ord) or die("Could not connect to database
$database
$hostnam e.");
$table = "students";
$fi
eld1 = "nam e";
$fi
eld2 = "sid";
$fi
eld3 = "gpa";
$fi
eld4 = "phone";
$value1 = "Zoidberg";
$value2 = 123456789;
$value3 = -4.0;
$value4 = "N /A";
$result = m ysql_query($sql);
$result = m ysql_query($sql);
$result = m ysql_query($sql);
w hile($record= m ysql_fetch_array($result))
print " < tr> \n";
{
print " < td> " . $record[$fi
eld1]. "< /td> \n";
print " < td> " . $record[$fi
eld2]. "< /td> \n";
print " < td> " . $record[$fi
eld3]. "< /td> \n";
print " < /tr> \n";
}
$num _records =
m ysql_num _row s($result);
w hile($record= m ysql_fetch_array($result))
print " < tr> \n";
{
print " < td> " . $record[$fi
eld1]. "< /td> \n";
print " < td> " . $record[$fi
eld2]. "< /td> \n";
print " < td> " . $record[$fi
eld3]. "< /td> \n";
print " < /tr> \n";
}