Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何统计mysql中以特定名称结尾的数据库_Php_Mysql_Count - Fatal编程技术网

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

Php 如何统计mysql中以特定名称结尾的数据库,php,mysql,count,Php,Mysql,Count,我想做的是,用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'],_

我想做的是,用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结尾的数据库名称的总数。谢谢你可以通过运行此查询来完成:

$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);
}
选择计数(*)
来自信息\u schema.schemata
其中,架构名称如“%\u 999”;

警告:第27行的mysqli_stmt_bind_param()预期参数1为mysqli_stmt,布尔值在C:\xampp\htdocs\ongrass\profile\db\dbsignins\createdb.php中给出警告:mysqli_stmt_execute()预期参数1为mysqli_stmt,布尔值在第28行的C:\xampp\htdocs\ongrass\profile\db\dbsignins\createdb.php中给出警告:mysqli_num_rows()参数1应该是mysqli_result,在第30行的C:\xampp\htdocs\ongrass\profile\db\dbsignins\createdb.php中给出布尔值。虽然这个代码片段可以解决这个问题,但确实有助于提高文章的质量。请记住,您是在将来为读者回答这个问题,那些人可能不知道您的原因r代码建议。使用上述代码,我可以选择数据库名称开头带有999_uu的数据库
"SHOW DATABASES WHERE `Database` LIKE '$baseid\_%'";