Adding Data to the Database

You can add name/value pairs to your open database with the function dba_insert(), which requires the name of a key, the value you want to store, and a valid DBA resource (as returned by dba_open()). This function returns true if all is well and false if an error occurs (such as an attempt to write to a database opened in read-only mode, or to overwrite an element of the same name). If the element you are attempting to insert already exists, the data is not overwritten.

Listing 12.1 creates or opens a database called products and adds some data to it.

Listing 12.1. Adding Items to 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> ...

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.