Amending Elements in a Database

You can amend an entry in a database with the dba_replace() function, which requires the name of a key, the new value to add, and a valid DBA resource. It returns true if all goes well and false if an error occurs. Listing 12.2 amends the code in Listing 12.1 so that keys are added regardless of existence.

Listing 12.2. Adding or Changing Items in a Database
 1: <!DOCTYPE html PUBLIC
 2:   "-//W3C//DTD XHTML 1.0 Strict//EN"
 3:   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 4: <html>
 5: <head>
 6: <title>Listing 12.2 Adding or Changing Items 7: in a database</title> 8: </head> 9: <body> 10: <div> 11: Adding products now... 12: <?php 13: $dbh = dba_open( "./data/products", "c", "gdbm" ) 14: or die( "Couldn't open ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.