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.
©2017, by Bill Sanders, all rights reserved.
This domain had 4,004 different visits in the last 30 days.
435,480 hits on this domain since 24 Nov 2006.
http://sandersongs.com/PHPsqlCourse/setupDB12.php
This page was last modified on our server on 4 Jun 2008
and last refreshed on our server at 12:32 pm, MST
This file took 0.00939 seconds to process.