如何计算 mysql 中以特定名称结尾的数据库

how to count databases in mysql ending with a particular name

我想做的是用 php 计算 mysql 中的数据库数量,我有一些数据库的名称如 corga_001,savage_900, bun_876, abc_999 , efg_999, hig_999。(我只想统计结尾有 _999 的数据库总数。

$id = 999;
$res = mysqli_query($conn,"SHOW DATABASES");
while ($row = mysqli_fetch_assoc($res)) {
echo count(strrchr($row['Database'],_ . $id) . "\n");}

上面的代码没有给我以 _999 结尾的数据库名称的总数,而是一次给我一个计数,因为它在循环中,我想要做的就是获取以 _999 结尾的数据库名称的总数_999.Thanks

$id = 999;

if ($stmt = mysqli_prepare($conn, 'SHOW DATABASES LIKE CONCAT("%_", ?)')
{
    mysqli_stmt_bind_param($stmt, "i", $id);
    mysqli_stmt_execute($stmt);
    echo mysqli_num_rows($stmt);
}

您只需 运行 这个查询就可以做到:

SELECT COUNT(*)
FROM information_schema.schemata
WHERE schema_name LIKE "%_999";
"SHOW DATABASES WHERE `Database` LIKE '$baseid\_%'";