05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Open the Control Panels folder, and double-click on the ODBC Data Sources icon.<br />

The resulting dialog box is the ODBC Data Source Administrator. Select the System<br />

DSN tab, click the Add button, and select the driver for your target database. If the<br />

driver is not listed, you will need to obtain one from your database vendor. If you’ve<br />

installed Microsoft Office products on your computer, you will have all the drivers<br />

that you need to use Excel as a primitive database. Figure 15-5 shows the addition of<br />

a System DSN for a Microsoft Excel workbook.<br />

Figure 15-5. Configuring a DSN for a Microsoft Excel spreadsheet located at C:\php\phonelist.xls<br />

Press the Configure button in the top window to select a specific workbook to use as<br />

the data source. In Figure 15-5, we’ve selected a workbook named phonelist.xls,<br />

located in the root-level <strong>PHP</strong> directory on drive C.<br />

Because ODBC must guess the data type of each column of data returned by a query,<br />

the only remaining configuration required is to specify the number of rows used to<br />

make this guess. In our example we used the default value of eight rows, meaning that<br />

eight rows of results will be looked at to try to determine the data type of each column.<br />

Once the selection and naming process is complete for your ODBC data source, click<br />

the OK button, and you will see that your new data source has been added to the list<br />

of System DSNs. From then on, you are ready to use the DSN.<br />

Accessing Excel Data<br />

Assuming we have an Excel spreadsheet with two columns, a list of phone extensions<br />

and a list of names, we could pull all records from the spreadsheet with the<br />

code shown in Example 15-4.<br />

368 | Chapter 15: <strong>PHP</strong> on Windows<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!