PHP Use Config ini
15/10/2005
use a .ini file to store your config data, for example the following file could be saved as config.ini:
;my configuration file
[general]
    site_name = "example site"
[database]
    host =  "my_db_host"
    db = "my_db"
    user = "my_db_user" 
    pass = "mypassword"

Then load the config with the following code:
$config = parse_ini_file('config.ini',true);

You can access the values with:
echo $config['database']['host'];

Open the CD tray
08/06/2005
Does what it says on the tin

<SCRIPT LANGUAGE="VBScript">
<!--
 
Set oWMP = CreateObject("WMPlayer.OCX.7" )
Set colCDROMs = oWMP.cdromCollection
 
if colCDROMs.Count >= 1 then
        For i = 0 to colCDROMs.Count - 1
                colCDROMs.Item(i).Eject
        Next ' cdrom
End If
 
-->
</SCRIPT>

Using MySQLi Prepared Statements
03/06/2005
Prepared statements provide the ability to create queries that are more secure, have better performance, and are more convenient to write.

The bound parameters do not need to be escaped.
<?php
$mysqli = new mysqli("localhost", "user", "password", "world");
 
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
 
/* prepare statement */
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country WHERE Code LIKE ? LIMIT 5")) {
 
    $stmt->bind_param("s", $code);
    $code = "C%";
 
    $stmt->execute();
 
    /* bind variables to prepared statement */
    $stmt->bind_result($col1, $col2);
 
    /* fetch values */
    while ($stmt->fetch()) {
        printf("%s %s\n", $col1, $col2);
    }
 
    /* close statement */
    $stmt->close();
}
/* close connection */
$mysqli->close();
 
?>

Convert age to dog years
01/06/2005
Converts human years to dog years.
### get the original age
age = input("Enter your age (in human years): ")
print		# print a blank line
 
### do some range checking, then print result
if age < 0:
	print "Negative age?!?  I don't think so."
elif age < 3 or age > 110:
	print "Frankly, I don't believe you."
else:
	print "That's", age*7, "in dog years."
 
### pause for Return key (so window doesn't disappear)
raw_input('press Return>')
Like Usage in SQL
28/04/2005
Searches for any occurence of bob
SELECT `death` FROM `bats` WHERE `name` LIKE '%bob%';
PHP Short If Statment
28/04/2005
Short if syntax:
condition ? true : false
<?php
 
$num = 1;
 
$ans = ($num == 1) ? "num is 1" : "num isn't 1";
 
echo $ans;
 
?>