keywords (SELECT, DELETE, FROM, WHERE) are case-insensitive
database, table, & column names are case-sensitive.
AUTO_INCREMENT - good for numeric keys:
CREATE TABLE cities (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), pop INT, founded DATE);
to take advantage of auto-incrementing, need to either leave out that column when updating/inserting, or specify NULL attribute
UPDATE <table>
SET <column> = <value>, <columnA> = <valueA>
WHERE ...
DELETE FROM <table>
WHERE ...
SELECT <column(s)>
FROM <table(s)>
WHERE ...
mysql> SELECT name, rank, salary FROM people; +--------------+----------+--------+ | name | rank | salary | +--------------+----------+--------+ | Jack Smith | Private | 23000 | | Jane Walker | General | 125000 | | June Sanders | Private | 22000 | | John Barker | Sergeant | 45000 | | Jim Castle | Sergeant | 38000 | +--------------+----------+--------+ mysql> SELECT rank, AVG(salary) FROM people GROUP BY rank; +----------+-------------+ | rank | AVG(salary) | +----------+-------------+ | General | 125000.0000 | | Private | 22500.0000 | | Sergeant | 41500.0000 | +----------+-------------+
REGEXP looks for the experession anywhere within the value being compared
So REGEXP 'Java' will match "Java", "Java for Dummies", and "Beginners Guide to Java"
The names of your php files need to end in *.php.
The first line of each file must be: #!/usr/local/bin/php
Example:
<html> ...(more html stuff)
<?php echo ("Hello World!\n"); ?>
Allowable syntax: From http://www.php.net/manual/en/language.basic-syntax.php
<?php echo("print stuff - good for XHTML\n"); ?>
<? echo ("this also works\n"); ?>
<?= expression ?> - shortcut for <? echo expression ?>
<script language="php">
echo ("some people use this syntax");
</script>
More advanced example: You can open & close php tags within an expression (such as an if statement or function block)
<?php
if ($expression) {
?>
<strong>This is true.</strong>
<?php
} else {
?>
<strong>This is false.</strong>
<?php
}
?>
Another example (with a function definition)
<?
function foo () {
echo "Enter foo...";
?>Some HTML inside foo...<?
echo "Leave foo.";
}
?>
<HTML><BODY>
<? foo(); ?>
</BODY></HTML>
produces:
Example
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
Form has:
<form action="action.php" method="POST"> Your age: <input type=text name="age"> <input type=submit> </form>Action.php contains:
You can also use $_REQUEST if you don't care whether the data was received from a POST or a GET request.
Example:
<?php
/* Connecting, selecting database */
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Could not connect");
print "Connected successfully";
mysql_select_db("my_database") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT * FROM my_table";
$result = mysql_query($query) or die("Query failed");
/* Printing results in HTML */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";
/* Free resultset */
mysql_free_result($result);
/* Closing connection */
mysql_close($link);
?>