📄 function.mysql-list-tables.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>List tables in a MySQL database</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-list-processes.html">mysql_list_processes</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mysql-num-fields.html">mysql_num_fields</a></div> <div class="up"><a href="ref.mysql.html">MySQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.mysql-list-tables" class="refentry"> <div class="refnamediv"> <h1 class="refname">mysql_list_tables</h1> <p class="verinfo">(PHP 4, PHP 5, PECL mysql:1.0)</p><p class="refpurpose"><span class="refname">mysql_list_tables</span> — <span class="dc-title">List tables in a MySQL database</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><b><b>mysql_list_tables</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$database</tt></span> [, <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$link_identifier</tt></span> ] )</div> <p class="para rdfs-comment"> Retrieves a list of table names from a MySQL database. </p> <p class="para"> This function is deprecated. It is preferable to use <a href="function.mysql-query.html" class="function">mysql_query()</a> to issue a SQL <i>SHOW TABLES [FROM db_name] [LIKE 'pattern']</i> statement instead. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">database</tt></i></span> <dd> <p class="para"> The name of the database </p> </dd> </dt> <dt><span class="term"><i><tt class="parameter">link_identifier</tt></i></span><dd><p class="para">The MySQL connection. If the link identifier is not specified, the last link opened by <a href="function.mysql-connect.html" class="function">mysql_connect()</a> is assumed. If no such link is found, itwill try to create one as if <a href="function.mysql-connect.html" class="function">mysql_connect()</a> was calledwith no arguments. If by chance no connection is found or established, an<b><tt>E_WARNING</tt></b> level error is generated.</p></dd></dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> A result pointer <a href="language.types.resource.html" class="type resource">resource</a> on success, or <b><tt>FALSE</tt></b> on failure. </p> <p class="para"> Use the <a href="function.mysql-tablename.html" class="function">mysql_tablename()</a> function to traverse this result pointer, or any function for result tables, such as <a href="function.mysql-fetch-array.html" class="function">mysql_fetch_array()</a>. </p> </div> <div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">4.3.7</td> <td colspan="1" rowspan="1" align="left"> This function became deprecated. </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 <b>mysql_list_tables()</b> alternative example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$dbname </span><span style="color: #007700">= </span><span style="color: #DD0000">'mysql_dbname'</span><span style="color: #007700">;<br /><br />if (!</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysql_host'</span><span style="color: #007700">, </span><span style="color: #DD0000">'mysql_user'</span><span style="color: #007700">, </span><span style="color: #DD0000">'mysql_password'</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">'Could not connect to mysql'</span><span style="color: #007700">;<br /> exit;<br />}<br /><br /></span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"SHOW TABLES FROM $dbname"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$result </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$result</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"DB Error, could not list tables\n"</span><span style="color: #007700">;<br /> echo </span><span style="color: #DD0000">'MySQL Error: ' </span><span style="color: #007700">. </span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">();<br /> exit;<br />}<br /><br />while (</span><span style="color: #0000BB">$row </span><span style="color: #007700">= </span><span style="color: #0000BB">mysql_fetch_row</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">)) {<br /> echo </span><span style="color: #DD0000">"Table: {$row[0]}\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">mysql_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: For backward compatibility, the following deprecated alias may be used: <b>mysql_listtables()</b> <br /> </p></blockquote> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.mysql-list-dbs.html" class="function" rel="rdfs-seeAlso">mysql_list_dbs()</a></li> <li class="member"><a href="function.mysql-tablename.html" class="function" rel="rdfs-seeAlso">mysql_tablename()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mysql-list-processes.html">mysql_list_processes</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mysql-num-fields.html">mysql_num_fields</a></div> <div class="up"><a href="ref.mysql.html">MySQL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -