11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 31 • INTRODUCING PDO0: Stores the SQLSTATE code as defined in the SQL standard1: Stores the database driver–specific error code2: Stores the database driver–specific error messageThe following script demonstrates errorInfo(), causing it to output error information pertinent to amissing table (in this case, the programmer mistakenly uses the singular form of the existing productstable):$query = "INSERT INTO product(id, sku, title)VALUES(NULL, 'SS873221', 'Surly Soap') ";$dbh->exec($query);print_r($dbh->errorInfo());Presuming the product table doesn’t exist, the following output is produced (formatted forreadability):Array ([0] => 42S02[1] => 1146[2] => Table 'chp31.product' doesn't exist )Getting and Setting AttributesQuite a few attributes are available for tweaking PDO’s behavior. Because the number of availableattributes is fairly large, in addition to the fact that several database drivers offer their own customattributes, it makes sense to point you to www.php.<strong>net</strong>/pdo for the latest information rather thanexhaustively list all available attributes here.The next section will cover the methods available for both setting and retrieving the values of theseattributes.Retrieving AttributesThe getAttribute() method retrieves the value of the attribute specified by attribute. Its prototypelooks like this:615

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!