PHP redirect

header("location: /newLocation.php");

of course before having printed any HTML (i.e. before setting headers).

SQLite and PHP primer

sqlite3SQLite (3.6+) is a database supporting a SQL-compatible syntax and does not rely on a server, rather it stores data on files. Here we’ll prime how to use SQLite from command line and how to integrate it with PHP (5.3+). Continue reading

PHP MySQL: MySQLi procedural tutorial

The deprecated mysql extension can be easily upgraded to the future proof mysqli, that supports both a procedural and an object-oriented syntax (creating some confusion at first when you find either one or the other in public forums…).
The procedural syntax is quite similar to the previous one, except for the mandatory “connection” argument.

Connection:
$conn = mysqli_connect($host, $user, $password, $database);
mysqli_select_db($conn, $database);
if (mysqli_connect_errno($conn)) {
trigger_error('DB conn failed: ' . mysqli_connect_error(), E_USER_ERROR);
}

For a typical query:

$sql = "SELECT * FROM ...";
$result = mysqli_query($conn, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ". mysqli_error($conn), E_USER_ERROR);

while ($row = mysqli_fetch_array($run)) {
print "$row[id]...\n";
}

More: http://markonphp.com/simple-select-mysqli-php/