php mysql get_PHP mysql_get_server_info 用法 手册 | 示例代码

这段代码展示了如何在没有实际连接MySQL服务器的情况下,通过PHP的`phpinfo()`函数来抓取MySQL客户端API版本信息。这在安装内容管理系统之前,帮助用户确认其MySQL版本是否兼容。代码首先开启输出缓冲,调用`phpinfo(INFO_MODULES)`,然后查找'ClientAPIversion'字符串,使用正则表达式匹配版本号并输出。
摘要由CSDN通过智能技术生成

Here is something I put together because I needed a way to pull the MySQL version number from the server without actually having a connection.  This was due to being part of a server info screen prior to installation of a cms.  Users need to know if their MySQL is supported or not prior to installation right? :)

This will scrape the phpinfo page looking for the MySQL row that says Client API version and return the version number after it.  This could also be used to scrape just about anything from the phpinfo page. :)

ob_start();

phpinfo(INFO_MODULES);

$info = ob_get_contents();

ob_end_clean();

$info = stristr($info, 'Client API version');

preg_match('/[1-9].[0-9].[1-9][0-9]/', $info, $match);

$gd = $match[0];

echo 'MySQL:  '.$gd.'
';

This will output:

MySQL: 4.1.22 (which is the version on my server)

I know this is crude but it's the only thing I could come up with and there isn't anything like this info available online so here it is.  I suck at preg_match and it would be helpful if someone could modify the string here to stand the test of time.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值