我需要一种快速,有效的方法,在一个mysql数据库中随机返回4个表的名称.表没有结构化的命名模式,除了它们都是小写字母和数字.
示例:my_database包含以下表格:
(cat, dog, boat, car, cars, cars35, accorns, accerns, speaker, shell, olympics, politics, fray, ttypo, ... (thousands of tables like this) ... , road)
Run Code Online (Sandbox Code Playgroud)
我需要一种有效的方法来返回一组没有重叠的随机表的名称.
例:
function_random_table(4) would return 4 table names stored to the following variables:
$random_1 = cars
$random_2 = cars35
$random_3 = shell
$random_4 = cat
Run Code Online (Sandbox Code Playgroud)
只需使用INFORMATION_SCHEMA.TABLES:
select table_name
from INFORMATION_SCHEMA.TABLES t
where TABLE_SCHEMA = 'YOUR_DB_NAME'
order by rand()
limit 4
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
136 次 |
| 最近记录: |