MANAGING CONTENT (Web site hosting) You pass three arguments to $stmt->bindParam():
MANAGING CONTENT You pass three arguments to $stmt->bindParam(): the name of the placeholder, the vari able that you want to use as its value, and a constant specifying the data type. The main constants are as follows: PDO::PARAM_INT: Integer (whole number) PDO::PARAM_LOB: Binary (such as an image, Word document, or PDF file) PDO::PARAM_STR: String (text) There doesn t appear to be a constant for floating point numbers, but the third argument is optional, so you can just leave it out. If you pass the variables as an associative array, you can t specify the data type. The PHP code for the same example using an associative array looks like this: // prepare statement $stmt = $conn->prepare($sql); // execute query by passing array of variables $stmt->execute(array(’:name’ => $_POST[’name’], ‘:pwd’ => . $_POST[’pwd’])); In both cases, the result of the query is stored in $stmt. Error messages can be accessed in the same way as with a PDO connection. However, instead of applying the errorInfo() method to the connection variable, apply it to the PDO statement like this: $error = $stmt->errorInfo(); if (isset($error[2])) { echo $error[2]; } Setting up a content management system Now that we ve got the theory out of the way, let s get on with something a bit more prac tical by building a content management system for a table called journal. Managing the content in a database table involves four stages, which I normally assign to four separate but interlinked pages, as follows: A page to insert new records A page to list all existing records A page to update existing records A page that asks for confirmation before deleting a record The list of records serves two purposes: first, to identify what s stored in the database; and more importantly, to link to the update and delete scripts by passing the record s primary key through a query string. As Figure 13-1 shows, you can put the details of the record into a form ready for editing or display sufficient details to confirm that the correct entry is being deleted. 347
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.