mysql show tables php

list all tables in a database with MySQLi

I have looked around and still can’t find how to list all my tables in a database. is it possible with MySQLi?

5 Answers 5

There are many ways.

Is the most simple SQL statement for doing that. You can also take a look at INFORMATION_SCHEMA.TABLES if you want to have more details or do some filtering or such.

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

Using PHP 5.5 or later, a simple solution is using PHP’s built-in array_column() function.

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

I’d try something like:

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

here is little example

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

Not the answer you’re looking for? Browse other questions tagged php mysql sql mysqli or ask your own question.

Linked

Related

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.9.17.40233

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

mysql_list_tables

mysql_list_tables — Возвращает список таблиц базы данных MySQL

Данная функция объявлена устаревшей в PHP 4.3.0, и, вместе с модулем MySQL, удалена PHP в 7.0.0. Вместо неё используйте активно развивающиеся модули MySQLi или PDO_MySQL. Так же смотрите раздел MySQL: выбор API. Альтернативы для этой функции:

Описание

Возвращает список имён таблиц базы данных MySQL.

Список параметров

Возвращаемые значения

Дескриптор результата ( resource ) в случае успешного выполнения или false в случае возникновения ошибки.

Список изменений

ВерсияОписание
4.3.7Функция помечена устаревшей.

Примеры

Пример #1 Пример использования mysql_list_tables()

Примечания

Для обратной совместимости может быть использован следующий устаревший псевдоним: mysql_listtables()

Смотрите также

User Contributed Notes 13 notes

The example by PHP-Guy to determine if a table exists is interesting and useful (thanx), except for one tiny detail. The function ‘mysql_list_tables()’ returns table names in lower case even when tables are created with mixed case. To get around this problem, add the ‘strtolower()’ function in the last line as follows:

A better alternative to mysql_list_tables() would be the following mysql_tables() function.

Even though php guy’s solution is probably the fastest here’s another one just for the heck of it.
I use this function to check whether a table exists. If not it’s created.

mysql_connect(«server»,»usr»,»pwd»)
or die(«Couldn’t connect!»);
mysql_select_db(«mydb»);

$tbl_exists = mysql_query(«DESCRIBE sometable»);
if (!$tbl_exists) <
mysql_query(«CREATE TABLE sometable (id int(4) not null primary key,
somevalue varchar(50) not null)»);
>

You can also do this with function mysql_query(). It’s better because mysql_list_tables is old function and you can stop showing errors.

So, this is the hack solution I came up with:

//You must have already created the «V2_Template» database.
//This will make a clone of it, including data.

okay everybody, the fastest, most accurate, safest method:

Note the «LIMIT 0», I mean come on, people, can’t get much faster than that! 🙂
As far as a query goes, this does absolutely nothing. But it has the ability to fail if the table doesnt exist, and that’s all you need!

Actually, the initially posted SELECT COUNT(*) approach is flawless. SELECT COUNT(*) will provide one and only one row in response unless you can’t select from the table at all. Even a brand new (empty) table responds with one row to tell you there are 0 records.

Источник

Show all tables inside a MySQL database using PHP?

I’m trying to show all the tables in my database. I’ve tried this:

but it only gives me one table name in a database I know has 2. What am I doing wrong?

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

5 Answers 5

How to get tables

1. SHOW TABLES

2. SHOW TABLES IN db_name

3. Using information schema

to OP

you have fetched just 1 row. fix like this:

and I think, information_schema would be better than SHOW TABLES

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

SHOW TABLE_NAME is not valid. Try SHOW TABLES

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

SHOW TABLES only lists the non-TEMPORARY tables in a given database.

Not the answer you’re looking for? Browse other questions tagged php mysql database or ask your own question.

Linked

Related

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.9.17.40233

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

MySQL SHOW TABLES: List Tables In a MySQL Database

Summary: in this tutorial, you will learn how to use the MySQL SHOW TABLES command to query tables in a particular database.

mysql show tables php. Смотреть фото mysql show tables php. Смотреть картинку mysql show tables php. Картинка про mysql show tables php. Фото mysql show tables php

To list tables in a MySQL database, you follow these steps:

The following illustrates the syntax of the MySQL SHOW TABLES command:

MySQL SHOW TABLES examples

The following example shows you how to list the table in the classicmodels database.

Step 1. Connect to the MySQL database server:

Step 2. Switch to classicmodels database:

Step 3. Show tables in the classicmodels database:

The SHOW TABLES command allows you to show if a table is a base table or a view. To include the table type in the result, you use the following form of the SHOW TABLES statement.

Let’s create a view in the classicmodels database called contacts that includes first name, last name and phone from the employees and customers tables for the demonstration.

Now, you issue the SHOW FULL TABLES command:

As you can see, all the tables are the base tables except for the contacts table which is a view.

For the database that has many tables, showing all tables at a time may not be intuitive.

Fortunately, the SHOW TABLES command provides you with an option that allows you to filter the returned tables using the LIKE operator or an expression in the WHERE clause as follows:

The following statement illustrates how to use the WHERE clause in the SHOW TABLES statement to list all the views in the classicmodels database.

Sometimes, you want to see the tables in the database that you are not connected to. In this case, you can use the FROM clause of the SHOW TABLES statement to specify the database from which you want to show the tables.

The following example demonstrates how to show tables that start with ‘time’ ;

It’s important to note that if you don’t have privileges for a base table or view, it won’t show up in the result set of the SHOW TABLES command.

In this tutorial, you have learned how to use the MySQL SHOW TABLES statement to list all tables in a particular database.

Источник

Displaying all table names in php from MySQL database

Alright, so I’m fairly new to PHP and SQL/MySQL so any help is appreciated.

I feel like I took the right approach. I searched php.net for «MySQL show all table names», it returned a deprecated method and suggested using a MySQL query on SHOW TABLES [FROM db_name] [LIKE ‘pattern’] I’m not sure what «pattern» means but, I searched for «SQL Wildcard» and got the «%» symbol. According to everything I found, this should work and output the table names at the end, but it does not. Any suggestions? Thanks in advance.

I get no errors. The output is exactly what’s echoed, but no table names.

8 Answers 8

The square brackets in your code are used in the mysql documentation to indicate groups of optional parameters. They should not be in the actual query.

The only command you actually need is:

If you want tables from a specific database, let’s say the database «books», then it would be

You only need the LIKE part if you want to find tables whose names match a certain pattern. e.g.,

would show you the names of tables that have «book» somewhere in the name.

Furthermore, just running the «show tables» query will not produce any output that you can see. SQL answers the query and then passes it to PHP, but you need to tell PHP to echo it to the page.

Since it sounds like you’re very new to SQL, I’d recommend running the mysql client from the command line (or using phpmyadmin, if it’s installed on your system). That way you can see the results of various queries without having to go through PHP’s functions for sending queries and receiving results.

If you have to use PHP, here’s a very simple demonstration. Try this code after connecting to your database:

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *