13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

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

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

246 Chapter 10 Working with Your <strong>MySQL</strong> Database<br />

Listing 10.1<br />

Continued<br />

(NULL, 2, 74.98, ‘2007-04-19’),<br />

(NULL, 3, 24.99, ‘2007-05-01’);<br />

insert into books values<br />

(‘0-672-31697-8’, ‘Michael Morgan’,<br />

‘Java 2 for Professional Developers’, 34.99),<br />

(‘0-672-31745-1’, ‘Thomas Down’, ‘Installing Debian GNU/Linux’, 24.99),<br />

(‘0-672-31509-2’, ‘Pruitt, et al.’, ‘Teach Yourself GIMP in 24 Hours’, 24.99),<br />

(‘0-672-31769-9’, ‘Thomas Schenk’,<br />

‘Caldera OpenLinux System Administration Unleashed’, 49.99);<br />

insert into order_items values<br />

(1, ‘0-672-31697-8’, 2),<br />

(2, ‘0-672-31769-9’, 1),<br />

(3, ‘0-672-31769-9’, 1),<br />

(3, ‘0-672-31509-2’, 1),<br />

(4, ‘0-672-31745-1’, 3);<br />

insert into book_reviews values<br />

(‘0-672-31697-8’, ‘The Morgan book is clearly written <strong>and</strong> goes well beyond<br />

most of the basic Java books out there.’);<br />

You can run this script from the comm<strong>and</strong> line by piping it through <strong>MySQL</strong> as follows:<br />

> mysql -h host -u bookorama -p books < /path/to/book_insert.sql<br />

Retrieving Data from the Database<br />

The workhorse of SQL is the SELECT statement. It’s used to retrieve data from a database<br />

by selecting rows that match specified criteria from a table.There are a lot of options <strong>and</strong><br />

different ways to use the SELECT statement.<br />

The basic form of a SELECT is<br />

SELECT [options] items<br />

[INTO file_details]<br />

FROM tables<br />

[ WHERE conditions ]<br />

[ GROUP BY group_type ]<br />

[ HAVING where_definition ]<br />

[ ORDER BY order_type ]<br />

[LIMIT limit_criteria ]<br />

[PROCEDURE proc_name(arguments)]<br />

[lock_options]<br />

;

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

Saved successfully!

Ooh no, something went wrong!