Using PHP to Access Tables

PHP functions for working with MySQL tables include:

Mysql_list_tables() takes a database name and returns a result pointer containing the tables available from the current database. The database is one parameter, and the specified link identifier ($link in our examples) is an optional second parameter.

<?php $link = @mysql_connect("mysql_host", "userid", "userpassword")     or die("Could not connect"); $db = @mysql_select_db("database_name",$link) or     die("Could not select database"); $tbl_list = @mysql_list_tables("database_name",$link) or     die("Could not retrieve table list"); $numrows = @mysql_num_rows($tbl_list); for ($i=0; $i<$numrows; $i++) {     echo mysql_tablename($tbl_list, $i) . "<br>"; } ?>

Similarly to mysql_db_name(), mysql_tablename() takes as its first parameter the result pointer from a call to mysql_list_tables() ($tbl_list in the example above). The second parameter is an index into the result set. If an error occurs, FALSE is returned. This function is always used in conjunction with mysql_list_tables.

Databases   < <  PREVIOUS   Table of Contents NEXT  > >   Queries

Developed with HTML-Kit
Sandersongs Web Tutorials
Contact the Webmasterwith comments.
©2018, by Bill Sanders, all rights reserved.
This domain had 3,946 different visits in the last 30 days.
457,057 hits on this domain since 24 Nov 2006.
This page was last modified on our server on 4 Jun 2008
and last refreshed on our server at 7:07 am, MST
This file took 0.01073 seconds to process.