Firefox 3
Quick navigation:


Updates records which meet given $condition.


ptb_update($filename, $location, $condition, $update);

Syntax description

name of file containing the database
location of $filename; can be:
globally defined (in ptb_ini.php) directory
local directory (ie. the same where script calling ptb_connect is placed)
other, defined directory, eg. /samples/db (no trailing slash)
filename (ie. absolute or relative path without DOCUMENT_ROOT dependency)
condition upon which records should be selected
new values for updated fields given in the form 'field' = 'value'; consecutive updates should be separated with commas


This function returns true on success and null (=false) on failure. Please notice that it returns true also when no changes has been made to the $filename.


ptb_update('author.php', 'L', "'author' == 'Arthur Conan Doyle'", "'country' = '3'");

You can change values of more than one field at a time; new assignments should be separated with commas:

ptb_update('books.php', '', "'id' == {$_GET['id']}", "'stock' = {$_POST['changeStock']}, 'price' = {$_POST['changePrice']}");


You can't use functions as a replacement directly; this won't work:

ptb_update('books.php', '', "'id' == '5'", "'published' = date('Y')");

To insert function's result, you must use new variable:

$year = date('Y'); ptb_update('books.php', '', "'id' == '5'", "'published' = $year");

The variable value is treated as a string, i.e. you can't use this:

$year = date('Y'); ptb_update('books.php', '', "'id' == '5'", "'published' = ($year + 1)");

You can still use functions in $condition, though:

$year = date('Y'); ptb_update('books.php', '', "'id' == date('Y') + 1", "'published' = $year");