欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

mysql strtolower_GitHub - redfoxli/mysqlstr: a php extension provide string processing of mysql

发布时间:2024/9/19 数据库 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 mysql strtolower_GitHub - redfoxli/mysqlstr: a php extension provide string processing of mysql 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

mysqlstr

Introduction

a php extension provide string processing of mysql

(strtolower && strtoupper base utf8)

把mysql里的字符串处理函数封装成php扩展,供php使用

目前只提供了utf8下的大写转小写以及小写转大写这两个功能

Why need this php ext

the result of strtolower(strtoupper) is different between php and mysql

efficiency

写这个扩展的目的有两个,一个是php的大小写转换函数和mysql的有一些区别,另外一个是性能问题

##Installation

$ /path/to/phpize

$ ./configure --with-php-config=/path/to/php-config

$ make

$ make install

add extension=mysqlstr.so in php.ini

Interface

strtoupper_utf8_ext

strtoupper_utf8_ext - make a utf8 string uppercase

Description

string strtoupper_utf8_ext(string str)

strtolower_utf8_ext

strtolower_utf8_ext - make a utf8 string lowercase

Description

string strtolower_utf8_ext(string str)

Example

case

$str = "High School D×DⅡ ";

$timeMB = microtime(true);

$resMb = mb_strtolower( $str, "UTF-8");

$timeMB = microtime(true) - $timeMB;

$timeSQL = microtime(true);

$resSQL = strtolower_utf8_ext($str);

$timeSQL = microtime(true) - $timeSQL;

echo "mbTime:" . sprintf("%.5f",$timeMB)." \n";

echo "sqlTime:" . sprintf("%.5f",$timeSQL)."\n";

echo "mbRes:" . $resMb . "\n";

echo "sqlRes:" . $resSQL . "\n";

result

mbTime:0.00004

sqlTime:0.00001

mbRes:high school d×dⅡ

sqlRes:high school d×dⅱ

efficiency case

$str = "High School D×DⅡ ";

$timeMB = microtime(true);

for($i=0;$i<30000;$i++)

$resMb = mb_strtolower( $str, "UTF-8");

$timeMB = microtime(true) - $timeMB;

$timeSQL = microtime(true);

for($i=0;$i<30000;$i++)

$resSQL = strtolower_utf8_ext($str);

$timeSQL = microtime(true) - $timeSQL;

echo "mbTime: " . sprintf("%.5f",$timeMB)." \n";

echo "sqlTime: " . sprintf("%.5f",$timeSQL)."\n";

result:

mbTime: 0.18481

sqlTime: 0.01055

More

String processing of mysql base mysql-5.1.74

More related analysis base Chinese is here

总结

以上是生活随笔为你收集整理的mysql strtolower_GitHub - redfoxli/mysqlstr: a php extension provide string processing of mysql的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。