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.

Getting More Information About Databases<br />

297<br />

to get a list of tables in the database.<br />

The statement<br />

show databases;<br />

displays a list of available databases.You can then use the SHOW TABLES statement to see a<br />

list of tables in one of those databases:<br />

show tables from books;<br />

When you use SHOW TABLES without specifying a database, it defaults to the one in use.<br />

When you know what the tables are, you can get a list of the columns:<br />

show columns from orders from books;<br />

If you leave off the database name, the SHOW COLUMNS statement will default to the database<br />

currently in use.You can also use the table.column notation:<br />

show columns from books.orders;<br />

One other useful variation of the SHOW statement can be used to see what privileges a<br />

user has. For example, if you run<br />

show grants for bookorama;<br />

you get the following output:<br />

+-----------------------------------------------------------------------+<br />

| Grants for bookorama@% |<br />

+-----------------------------------------------------------------------+<br />

| GRANT USAGE ON *.* TO ‘bookorama’@’%’ |<br />

| IDENTIFIED BY PASSWORD ‘*1ECE648641438A28E1910D0D7403C5EE9E8B0A85’ |<br />

| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER |<br />

| ON `books`.* TO ‘bookorama’@’%’ |<br />

+-----------------------------------------------------------------------+<br />

The GRANT statements shown are not necessarily the ones that were executed to give<br />

privileges to a particular user, but rather summary equivalent statements that would<br />

produce the user’s current level of privilege.<br />

Many other variations of the SHOW statement can be used as well. In fact, there are<br />

over 30 variations of the SHOW statement. Some of the more popular variations are shown<br />

in Table 12.7. For a complete list, see the <strong>MySQL</strong> Manual entry at http://dev.<br />

mysql.com/doc/refman/5.1/en/show.html. In all instances of [like_or_where] in the<br />

examples below, you can attempt to match a pattern using LIKE or an expression using<br />

WHERE.

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

Saved successfully!

Ooh no, something went wrong!