php下pdo的mysql事务处理应用实例


php+mysql事务处理的几个步骤:
1.关闭自动提交
2.开启事务处理
3.有异常就自动抛出异常提示再回滚
4.开启自动提交

注意:mysql只有这个InnoDB驱动是支持事务处理的,默认MyIsAM驱动不支持.
下面是实例代码:

阅读全文

shell 脚本检查某目录下php文件语法


check_php_syntax.sh

#!/bin/bash
# check php syntax
if [ $# -lt 1 ];then
    echo 'Usage: ' $0  'directory';
    exit
fi
if [ ! -d $1 ];then
    echo $1  'not a directory,please check!';
    exit
fi
directory=$1
temp_file="/tmp/file$$"
#echo $temp_file
ls -R $directory | awk  '
    BEGIN{
        FS="n"   
        folder="'$directory'"
        logname="'$temp_file'"
    }
    {
        if($0~/.php$/){
            system("php -l " folder "/" $0  "   >>  " logname  " 2>&1") 
        }
        if($0~/:$/){
            folder=substr($1,1,length($1)-1)
        }
    }
'
if [ -e $temp_file ];then
    cat $temp_file | awk '
        BEGIN{
            error = 0
       }
        {
            if($0~/Parse/) {
                error++
                errorfile[$0] = $0
            }  
        }
        END{
            print "错误文件:" error "个"
            if(length(errorfile)>0) print "错误行数:"
                for (i in errorfile)
                    print i
        }
    '
else
    echo "php file not found."
    exit;
fi

阅读全文

php树形结构数据存取实例类


<?php
/**
 * Tanphp framework
 *
 *
 * @category   Tanphp
 * @package    Data_structure
 * @copyright  Copyright (c) 2012 谭博  tanbo.name
 * @version    $Id: Tree.php 25024 2012-11-26 22:22:22 tanbo $
 */

阅读全文

php生成随机颜色代码实例

本文章给各位同学介绍php生成随机颜色代码实例,有需要了解学习的朋友可参考。  代码如下 复制代码 function randrgb() {   $str='0123456789ABCDEF';     $estr='#';     $len=strlen($str);     for($i=1;$i<=6;$i++)     {&nbs...
阅读全文

php 获取flash的尺寸信息实例

print_r(getimagesize('http://www.phprm.com/logo.jpg'));
输出的结果为:
Array
(
    [0] => 550
    [1] => 190
    [2] => 3
    [3] => width="550" height="190"
    [bits] => 8
    [mime] => image/png
)

阅读全文