标签 PHP 下的文章

突然想到这个方法,果然已经有人实现了。

有这个脚本也能看出来,数据表的很多信息都保存在INFORMATION_SCHEMA.TABLES表里,还有数据表注释的重要性!


 */

//配置数据库
$dbserver   = "localhost";
$dbusername = "root";
$dbpassword = "root";
$database   = 'mydb';
//其他配置
$title = '系统数据字典';

$mysql_conn = @mysql_connect("$dbserver", "$dbusername", "$dbpassword") or die("Mysql connect is error.");
mysql_select_db($database, $mysql_conn);
mysql_query('SET NAMES utf8', $mysql_conn);
$table_result = mysql_query('show tables', $mysql_conn);
//取得所有的表名
while ($row = mysql_fetch_array($table_result)) {
    $tables[]['TABLE_NAME'] = $row[0];
}

//循环取得所有表的备注
foreach ($tables AS $k=>$v) {
    $sql  = 'SELECT * FROM ';
    $sql .= 'INFORMATION_SCHEMA.TABLES ';
    $sql .= 'WHERE ';
    $sql .= "table_name = '{$v['TABLE_NAME']}'  AND table_schema = '{$database}'";
    $table_result = mysql_query($sql, $mysql_conn);
    while ($t = mysql_fetch_array($table_result) ) {
        $tables[$k]['TABLE_COMMENT'] = $t['TABLE_COMMENT'];
    }

    $sql  = 'SELECT * FROM ';
    $sql .= 'INFORMATION_SCHEMA.COLUMNS ';
    $sql .= 'WHERE ';
    $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'";

    $fields = array();
    $field_result = mysql_query($sql, $mysql_conn);
    while ($t = mysql_fetch_array($field_result) ) {
        $fields[] = $t;
    }
    $tables[$k]['COLUMN'] = $fields;
}
mysql_close($mysql_conn);


$html = '';
//循环所有表
foreach ($tables AS $k=>$v) {
    $html .= '

'. $v['TABLE_COMMENT'] . ' 

'; $html .= ''; $html .= ''; $html .= ''; $html .= ''; foreach ($v['COLUMN'] AS $f) { $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; $html .= ''; } $html .= '
' . $v['TABLE_NAME'] . '
字段名数据类型默认值 允许非空 自动递增备注
' . $f['COLUMN_NAME'] . '' . $f['COLUMN_TYPE'] . ' ' . $f['COLUMN_DEFAULT'] . ' ' . $f['IS_NULLABLE'] . '' . ($f['EXTRA']=='auto_increment'?'是':' ') . ' ' . $f['COLUMN_COMMENT'] . '

'; } //输出 echo ' ' . $title . ' '; echo '

' . $title . '

'; echo $html; echo '';

修改一下用户名密码即可,之后打印成PDF即可分发给团队成员使用了。

转自http://www.cnblogs.com/zemliu/archive/2012/06/04/2533555.html

准备

PHP的安装最头疼的就是因为某些类库没有安装而报错,所以编译前请确保以下包已安装

yum groupinstall "development tools"

yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl curl-devel openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel

编译

高大上的编译选项

./configure  \
--prefix=/usr/local/php  \
--enable-fpm  \
--with-curl  \
--with-openssl  \
--enable-mbregex  \
--with-mysql  \
--with-mysqli  \
--with-mysql-sock  \
--enable-pdo  \
--with-pdo-mysql  \
--with-pdo-pgsql  \
--with-pdo-sqlite  \
--enable-mysqlnd  \
--with-gd  \
--enable-gd-native-ttf  \
--enable-exif  \
--with-jpeg-dir=/usr/local/jpeg  \
--with-png-dir=/usr/local/png  \
--with-freetype-dir=/usr/local/freetype  \
--enable-gd-jis-conv  \
--with-gettext  \
--with-zlib  \
--enable-zip  \
--with-bz2  \
--disable-fileinfo  \
--enable-xmlreader  \
--enable-xmlwriter  \
--with-xmlrpc  \
--enable-mbstring  \
--enable-inline-optimization \

20150524更新 5.6.9编译配置选项,推荐使用

./configure --prefix=/usr/local/php --with-pdo-pgsql --with-pdo-sqlite --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-xmlreader --enable-xmlwriter --enable-soap --enable-calendar --with-curl --with-mcrypt --with-zlib --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-pdo-mysql --with-mysqli --with-mysql-sock --enable-mysqlnd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --enable-ftp --with-imap=/usr/local/php-imap --with-imap-ssl --with-kerberos --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --disable-fileinfo

编译中出了问题请参考

彻底解决编译PHP找不到libc-client.a的问题

PHP编译错误的解决办法

如果内存小于1G,需要加上--disable-fileinfo

找到二进制文件

添加环境变量

whereis php
#/usr/local/bin/php
echo $PATH
#/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export PATH=/usr/local/php/bin:$PATH
echo $PATH
#/usr/local/php/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
php -v
#PHP 5.6.0 (cli) (built: Sep 10 2014 23:54:43)

编辑profile

ps./etc/profile:在登录时,操作系统定制用户环境时使用的第一个文件,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行

pss./etc/environment:在登录时操作系统使用的第二个文件,系统在读取你自己的profile前,设置环境文件的环境变量。

pss.~/.bash_profile:在登录时用到的第三个文件是.profile文件,每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该 文件仅仅执行一次!默认情况下,他设置一些环境变游戏量,执行用户的.bashrc文件。/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.

pss.~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。

vim /etc/profile

在最后一行加上:export PATH="/usr/local/php/bin:$PATH"

最后:

source /etc/profile

或者直接把php拷贝至/usr/local/bin/

cp /usr/local/php/bin/php /usr/local/bin/

配置文件

cp /tmp/php-5.6.0/php.ini-production /usr/local/php/etc/php.ini

启动php-fpm

/usr/local/php/sbin/php-fpm

运行时指定配置文件

/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

开机自启动

echo "/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf" >> /etc/rc.local

或者

vim /etc/rc.local

# ADD
/usr/local/php/sbin/php-fpm -c /usr/local/php/etc/php.ini -y /usr/local/php/etc/php-fpm.conf

配置php-fpm

配置文件路径/usr/local/php/etc/php-fpm.conf

扩展阅读

PHP安装配置Opcache加速你的网站

PHP安装memcached扩展

PHP之负载均衡下的session共用(Memcache实现)

This article is post on https://coderwall.com/p/ggmpfa

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum -y install libxslt-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

yum -y install net-snmp-devel

configure: error: Please reinstall readline - I cannot find readline.h

yum -y install readline-devel

configure: error: Cannot find pspell

yum -y install aspell-devel

checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!

yum -y install unixODBC-devel

configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.

yum -y install libicu-devel

configure: error: utf8mime2text() has new signature, but U8TCANONICAL is missing. This should not happen. Check config.log for additional information.

yum -y install libc-client-devel

configure: error: freetype.h not found.

yum -y install freetype-devel

configure: error: xpm.h not found.

yum -y install libXpm-devel

configure: error: png.h not found.

yum -y install libpng-devel

configure: error: vpx_codec.h not found.

yum -y install libvpx-devel

configure: error: Cannot find enchant

yum -y install enchant-devel

configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/

yum -y install libcurl-devel

LAOGAO added 20140907:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install

added 20141003:

Cannot find imap

ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so

configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing.

yum -y install libc-client-devel

Cannot find ldap.h

yum -y install openldap
yum -y install openldap-devel

configure: error: Cannot find ldap libraries in /usr/lib

cp -frp /usr/lib64/libldap* /usr/lib/

configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

yum -y install postgresql-devel

configure: error: Please reinstall the lib curl distribution

yum -y install curl-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

yum -y install net-snmp-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

yum -y install libxslt-devel

checking for BZip2 support… yes checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution

Fix:

yum -y install bzip2-devel

checking for cURL support… yes checking if we should use cURL for url streams… no checking for cURL in default path… not found configure: error: Please reinstall the libcurl distribution – easy.h should be in/include/curl/

Fix:

yum -y install curl-devel

checking for curl_multi_strerror in -lcurl… yes checking for QDBM support… no checking for GDBM support… no checking for NDBM support… no configure: error: DBA: Could not find necessary header file(s).

Fix:

yum -y install db4-devel

checking for fabsf… yes checking for floorf… yes configure: error: jpeglib.h not found.

Fix:

yum -y install libjpeg-devel

checking for fabsf… yes checking for floorf… yes checking for jpeg_read_header in -ljpeg… yes configure: error: png.h not found.

Fix:

yum -y install libpng-devel

checking for png_write_image in -lpng… yes If configure fails try –with-xpm-dir=

configure: error: freetype.h not found. Fix:

Reconfigure your PHP with the following option. --with-xpm-dir=/usr

checking for png_write_image in -lpng… yes configure: error: libXpm.(a|so) not found.

Fix:

yum -y install libXpm-devel

checking for bind_textdomain_codeset in -lc… yes checking for GNU MP support… yes configure: error: Unable to locate gmp.h

Fix:

yum -y install gmp-devel

checking for utf8_mime2text signature… new checking for U8T_DECOMPOSE… configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.

Fix:

yum -y install libc-client-devel

checking for LDAP support… yes, shared checking for LDAP Cyrus SASL support… yes configure: error: Cannot find ldap.h

Fix:

yum -y install openldap-devel

checking for mysql_set_character_set in -lmysqlclient… yes checking for mysql_stmt_next_result in -lmysqlclient… no checking for Oracle Database OCI8 support… no checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!

Fix:

yum -y install unixODBC-devel

checking for PostgreSQL support for PDO… yes, shared checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix:

yum -y install postgresql-devel

checking for sqlite 3 support for PDO… yes, shared checking for PDO includes… (cached) /usr/local/src/php-5.3.7/ext checking for sqlite3 files in default path… not found configure: error: Please reinstall the sqlite3 distribution

Fix:

yum -y install sqlite-devel

checking for utsname.domainname… yes checking for PSPELL support… yes configure: error: Cannot find pspell

Fix:

yum -y install aspell-devel

checking whether to enable UCD SNMP hack… yes checking for default_store.h… no

checking for kstat_read in -lkstat… no checking for snmp_parse_oid in -lsnmp… no checking for init_snmp in -lsnmp… no configure: error: SNMP sanity check failed. Please check config.log for more information.

Fix:

yum -y install net-snmp-devel

checking whether to enable XMLWriter support… yes, shared checking for xml2-config path… (cached) /usr/bin/xml2-config checking whether libxml build works… (cached) yes checking for XSL support… yes, shared configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix:

yum -y install libxslt-devel

configure: error: xml2-config not found. Please check your libxml2 installation.

Fix:

yum -y install libxml2-devel

checking for PCRE headers location… configure: error: Could not find pcre.h in /usr

Fix:

yum -y install pcre-devel

configure: error: Cannot find MySQL header files under yes. Note that the MySQL client library is not bundled anymore!

Fix:

yum -y install mysql-devel

checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!

Fix:

yum -y install unixODBC-devel

checking for pg_config… not found configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

Fix:

yum -y install postgresql-devel

configure: error: Cannot find pspell

Fix:

yum -y install pspell-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

Fix:

yum -y install net-snmp-devel

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

Fix:

yum -y install libxslt-devel

PHP在处理正则表达式的时候,在最后面可以加上诸如/i, /is, /s, /isU的选项,他们都代表什么含义呢?

其实他们是PHP正则表达式的模式修正符,用于对正则表达式的补充。

优先级概念

正则符号的优先级:

()圆括号因为是内存处理所以第1 * ? + { } 重复匹配内容第2 ^ $ \b 边界处理第3 | 条件处理第4 最后按照运算顺序计算匹配

常用的修正符

i

(PCRE_CASELESS)正则内容在匹配时候不区分大小写(默认是区分的)。

preg_match('/\[TOC\]/i',$str) 这句话中的小写字母i,他跟在正则表达式后面,起的作用是匹配时忽略大小写 所以,上述正则表达式可以匹配诸如 [toc]、[ToC]、或者[TOC]。

m

(PCRE_MULTILINE) 在匹配首内容或者尾内容时候采用多行识别匹配。默认情况下,PCRE 将目标字符串作为单一的一“行”字符所组成的(甚至其中包含有换行符也是如此)。“行起始”元字符(^)仅仅匹配字符串的起始,“行结束”元字符($)仅仅匹配字符串的结束,或者最后一个字符是换行符时其前面(除非设定了 D 修正符)。这和 Perl 是一样的。 当设定了此修正符,“行起始”和“行结束”除了匹配整个字符串开头和结束外,还分别匹配其中的换行符的之后和之前。这和 Perl 的 /m 修正符是等效的。如果目标字符串中没有“/n”字符或者模式中没有 ^ 或 $,则设定此修正符没有任何效果。

S

(PCRE_DOTALL) 如果没有使用这个模式修正符号,元字符中的"."默认不能表示换行符号,将字符串视为单行。如果设定了此修正符,模式中的圆点元字符(.)匹配所有的字符,包括换行符。没有此设定的话,则不包括换行符。这和 Perl 的 /s 修正符是等效的。排除字符类例如 [^a] 总是匹配换行符的,无论是否设定了此修正符。

x

(PCRE_EXTENDED) 忽略正则中的空白。如果设定了此修正符,模式中的空白字符除了被转义的或在字符类中的以外完全被忽略,在未转义的字符类之外的 # 以及下一个换行符之间的所有字符,包括两头,也都被忽略。

A

(PCRE_ANCHORED) 强制从头开始匹配。如果设定了此修正符,模式被强制为“anchored”,即强制仅从目标字符串的开头开始匹配即自动在模式开头加上^。此效果也可以通过适当的模式本身来实现(在 Perl 中实现的唯一方法)。

D

(PCRE_DOLLAR_ENDONLY) 强制$匹配尾部无任何内容。如果设定了此修正符,模式中的美元元字符仅匹配目标字符串的结尾。没有此选项时,如果最后一个字符是换行符的话,美元符号也会匹配此字符之前(但不会匹配任何其它换行符之前)。如果设定了 m 修正符则忽略此选项。Perl 中没有与其等价的修正符。 S 当一个模式将被使用若干次时,为加速匹配起见值得先对其进行分析。如果设定了此修正符则会进行额外的分析。目前,分析一个模式仅对没有单一固定起始字符的 non-anchored 模式有用。

U

(PCRE_UNGREEDY) 禁止贪婪匹配 只跟踪到最近的一个匹配符并结束,常用在采集程序上的正则表达式。本修正符反转了匹配数量的值使其不是默认的重复,而变成在后面跟上“?”才变得重复。这和 Perl 不兼容。也可以通过在模式之中设定 (?U) 修正符来启用此选项。

X

(PCRE_EXTRA) 此修正符启用了一个PCRE中与Perl不兼容的额外功能。模式中的任何反斜线后面跟上一个没有特殊意义的字母导致一个错误,从而保留此组合以备将来扩充。默认情况下,和Perl一样,一个反斜线后面跟一个没有特殊意义的字母被当成该字母本身。当前没有其它特性受此修正符控制。即:贪婪模式,最大限度匹配如:/a[/w]+?e/U匹配abceadeddd中的abceade而不是abce,如果不加U修正,则匹配abceu(PCRE_UTF8)此修正符启用了一个PCRE中与Perl不兼容的额外功能。模式字符串被当成UTF-8。本修正符在Unix下自PHP4.1.0起可用,在win32下自PHP4.2.3起可用。

参考PHP>手册>函数参考>文本处理>PCRE>PCRE模式