ptb_update
Updates records which meet given $condition.
Syntax
ptb_update($filename, $location, $condition, $update);
Syntax description
- $filename
- name of file containing the database
- $location
- location of $filename; can be:
- G
- globally defined (in ptb_ini.php) directory
- L
- local directory (ie. the same where script calling ptb_connect is placed)
- <path>
- other, defined directory, eg. /samples/db (no trailing slash)
- F
- filename (ie. absolute or relative path without DOCUMENT_ROOT dependency)
- $condition
- condition upon which records should be selected
- $update
- new values for updated fields given in the form 'field' = 'value'; consecutive updates should be separated with commas
Return
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.
Sample(s)
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']}");
Limitations
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");