ホームページ  >  記事  >  php教程  >  ecshop适应PHP7的修改 - 龙翔天下

ecshop适应PHP7的修改 - 龙翔天下

WBOY
WBOYオリジナル
2016-05-20 10:14:561887ブラウズ

说实话,ecshop这个系统,到目前也没见怎么推出新版本,如果是新项目,不太建议使用它。不过,因为我一直以来都在使用中,所以不得不更改让其适应PHP新版本。现在PHP 7已经出发行版了,所以更改来继续使用吧。具体的更改有以下方面:

(1)将mysql扩展的使用替换掉,改为使用mysqli或pdo:

从php5.5开始,mysql扩展将废弃了。

具体更改的文件在于includes/cls_mysql.php。这是个不小的工程,文件代码太长……

<span style="color: #0000ff;">if</span> (!<span style="color: #008080;">defined</span>('DITAN_ECS'<span style="color: #000000;">))
{
    </span><span style="color: #0000ff;">die</span>('Hacking attempt'<span style="color: #000000;">);
}

</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> cls_mysql
{
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$link_id</span>    = <span style="color: #0000ff;">NULL</span><span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$settings</span>   = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$queryCount</span> = 0<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$queryTime</span>  = ''<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$queryLog</span>   = <span style="color: #0000ff;">array</span><span style="color: #000000;">();

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$max_cache_time</span> = 300; <span style="color: #008000;">//</span><span style="color: #008000;"> 最大的缓存时间,以秒为单位</span>

    <span style="color: #0000ff;">var</span> <span style="color: #800080;">$cache_data_dir</span> = 'temp/query_caches/'<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$root_path</span>      = ''<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$error_message</span>  = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$platform</span>       = ''<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$version</span>        = ''<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$dbhash</span>         = ''<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$starttime</span>      = 0<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$timeline</span>       = 0<span style="color: #000000;">;
    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$timezone</span>       = 0<span style="color: #000000;">;
    </span><span style="color: #008000;">//</span><span style="color: #008000;"> 事务指令数</span>
    <span style="color: #0000ff;">protected</span> <span style="color: #800080;">$transTimes</span> = 0<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$mysql_config_cache_file_time</span> = 0<span style="color: #000000;">;

    </span><span style="color: #0000ff;">var</span> <span style="color: #800080;">$mysql_disable_cache_tables</span> = <span style="color: #0000ff;">array</span>(); <span style="color: #008000;">//</span><span style="color: #008000;"> 不允许被缓存的表,遇到将不会进行缓存</span>

    <span style="color: #0000ff;">function</span> __construct(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span> = '', <span style="color: #800080;">$charset</span> = 'gbk', <span style="color: #800080;">$pconnect</span> = 0, <span style="color: #800080;">$quiet</span> = 0<span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$this</span>->cls_mysql(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span>, <span style="color: #800080;">$charset</span>, <span style="color: #800080;">$pconnect</span>, <span style="color: #800080;">$quiet</span><span style="color: #000000;">);
    }

    </span><span style="color: #0000ff;">function</span> cls_mysql(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span> = '', <span style="color: #800080;">$charset</span> = 'gbk', <span style="color: #800080;">$pconnect</span> = 0, <span style="color: #800080;">$quiet</span> = 0<span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">defined</span>('EC_CHARSET'<span style="color: #000000;">))
        {
            </span><span style="color: #800080;">$charset</span> = <span style="color: #008080;">strtolower</span>(<span style="color: #008080;">str_replace</span>('-', '',<span style="color: #000000;"> EC_CHARSET));
        }

        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">defined</span>('ROOT_PATH') && !<span style="color: #800080;">$this</span>-><span style="color: #000000;">root_path)
        {
            </span><span style="color: #800080;">$this</span>->root_path =<span style="color: #000000;"> ROOT_PATH;
        }

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$quiet</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->connect(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span>, <span style="color: #800080;">$charset</span>, <span style="color: #800080;">$pconnect</span>, <span style="color: #800080;">$quiet</span><span style="color: #000000;">);
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$this</span>->settings = <span style="color: #0000ff;">array</span><span style="color: #000000;">(
                                    </span>'dbhost'   => <span style="color: #800080;">$dbhost</span>,
                                    'dbuser'   => <span style="color: #800080;">$dbuser</span>,
                                    'dbpw'     => <span style="color: #800080;">$dbpw</span>,
                                    'dbname'   => <span style="color: #800080;">$dbname</span>,
                                    'charset'  => <span style="color: #800080;">$charset</span>,
                                    'pconnect' => <span style="color: #800080;">$pconnect</span><span style="color: #000000;">
                                    );
        }
    }

    </span><span style="color: #0000ff;">function</span> connect(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span>, <span style="color: #800080;">$dbname</span> = '', <span style="color: #800080;">$charset</span> = 'utf8', <span style="color: #800080;">$pconnect</span> = 0, <span style="color: #800080;">$quiet</span> = 0<span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$pconnect</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->link_id = <span style="color: #0000ff;">new</span> mysqli('p:'.<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span><span style="color: #000000;">);
            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">connect_error)
            {
                </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$quiet</span><span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$this</span>->ErrorMsg("Can't pConnect MySQL Server(<span style="color: #800080;">$dbhost</span>)!"<span style="color: #000000;">);
                }

                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
            }
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$this</span>->link_id = <span style="color: #0000ff;">new</span> mysqli(<span style="color: #800080;">$dbhost</span>, <span style="color: #800080;">$dbuser</span>, <span style="color: #800080;">$dbpw</span><span style="color: #000000;">);

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">connect_error)
            {
                </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$quiet</span><span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$this</span>->ErrorMsg("Can't Connect MySQL Server(<span style="color: #800080;">$dbhost</span>)!"<span style="color: #000000;">);
                }

                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
            }
        }

        </span><span style="color: #800080;">$this</span>->dbhash  = <span style="color: #008080;">md5</span>(<span style="color: #800080;">$this</span>->root_path . <span style="color: #800080;">$dbhost</span> . <span style="color: #800080;">$dbuser</span> . <span style="color: #800080;">$dbpw</span> . <span style="color: #800080;">$dbname</span><span style="color: #000000;">);
        </span><span style="color: #800080;">$this</span>->version = <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">server_version;

        </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 对字符集进行初始化 </span><span style="color: #008000;">*/</span>
        <span style="color: #800080;">$this</span>->link_id->set_charset(<span style="color: #800080;">$charset</span><span style="color: #000000;">);
        
        </span><span style="color: #800080;">$this</span>->link_id->query("SET sql_mode=''"<span style="color: #000000;">);
        </span><span style="color: #800080;">$sqlcache_config_file</span> = <span style="color: #800080;">$this</span>->root_path . <span style="color: #800080;">$this</span>->cache_data_dir . 'sqlcache_config_file_' . <span style="color: #800080;">$this</span>->dbhash . '.php'<span style="color: #000000;">;

        @</span><span style="color: #0000ff;">include</span>(<span style="color: #800080;">$sqlcache_config_file</span><span style="color: #000000;">);

        </span><span style="color: #800080;">$this</span>->starttime = <span style="color: #008080;">time</span><span style="color: #000000;">();

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->max_cache_time && <span style="color: #800080;">$this</span>->starttime > <span style="color: #800080;">$this</span>->mysql_config_cache_file_time + <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time)
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$dbhost</span> != '.'<span style="color: #000000;">)
            {
                </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->link_id->query("SHOW VARIABLES LIKE 'basedir'"<span style="color: #000000;">);
                </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$result</span>-><span style="color: #000000;">fetch_array(MYSQLI_ASSOC);
                </span><span style="color: #800080;">$result</span>-><span style="color: #000000;">free();
                </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$row</span>['Value']{1}) && <span style="color: #800080;">$row</span>['Value']{1} == ':' && !<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$row</span>['Value']{2}) && <span style="color: #800080;">$row</span>['Value']{2} == "/"<span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$this</span>->platform = 'WINDOWS'<span style="color: #000000;">;
                }
                </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
                {
                    </span><span style="color: #800080;">$this</span>->platform = 'OTHER'<span style="color: #000000;">;
                }
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
            {
                </span><span style="color: #800080;">$this</span>->platform = 'WINDOWS'<span style="color: #000000;">;
            }

            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->platform == 'OTHER' &&<span style="color: #000000;">
                (</span><span style="color: #800080;">$dbhost</span> != '.' && <span style="color: #008080;">strtolower</span>(<span style="color: #800080;">$dbhost</span>) != 'localhost:3306' && <span style="color: #800080;">$dbhost</span> != '127.0.0.1:3306') ||<span style="color: #000000;">
                date_default_timezone_get() </span>== 'UTC'<span style="color: #000000;">)
            {
                </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->link_id->query("SELECT UNIX_TIMESTAMP() AS timeline, UNIX_TIMESTAMP('" . <span style="color: #008080;">date</span>('Y-m-d H:i:s', <span style="color: #800080;">$this</span>->starttime) . "') AS timezone"<span style="color: #000000;">);
                </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$result</span>-><span style="color: #000000;">fetch_array(MYSQLI_ASSOC);
                </span><span style="color: #800080;">$result</span>-><span style="color: #000000;">free();
                </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$dbhost</span> != '.' && <span style="color: #008080;">strtolower</span>(<span style="color: #800080;">$dbhost</span>) != 'localhost:3306' && <span style="color: #800080;">$dbhost</span> != '127.0.0.1:3306'<span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$this</span>->timeline = <span style="color: #800080;">$this</span>->starttime - <span style="color: #800080;">$row</span>['timeline'<span style="color: #000000;">];
                }
                </span><span style="color: #0000ff;">if</span> (date_default_timezone_get() == 'UTC'<span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$this</span>->timezone = <span style="color: #800080;">$this</span>->starttime - <span style="color: #800080;">$row</span>['timezone'<span style="color: #000000;">];
                }
            }

            </span><span style="color: #800080;">$content</span> = 'mysql_config_cache_file_time = ' . <span style="color: #800080;">$this</span>->starttime . ";\r\n" .
                       '$this->timeline = ' . <span style="color: #800080;">$this</span>->timeline . ";\r\n" .
                       '$this->timezone = ' . <span style="color: #800080;">$this</span>->timezone . ";\r\n" .
                       '$this->platform = ' . "'" . <span style="color: #800080;">$this</span>->platform . "';\r\n?" . '>'<span style="color: #000000;">;

            @</span><span style="color: #008080;">file_put_contents</span>(<span style="color: #800080;">$sqlcache_config_file</span>, <span style="color: #800080;">$content</span><span style="color: #000000;">);
        }

        </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 选择数据库 </span><span style="color: #008000;">*/</span>
        <span style="color: #0000ff;">if</span> (<span style="color: #800080;">$dbname</span><span style="color: #000000;">)
        {
            
            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id->select_db(<span style="color: #800080;">$dbname</span>) === <span style="color: #0000ff;">false</span><span style="color: #000000;"> )
            {
                </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$quiet</span><span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$this</span>->ErrorMsg("Can't select MySQL database(<span style="color: #800080;">$dbname</span>)!"<span style="color: #000000;">);
                }

                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
            {
                </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            }
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;
        }
    }

    </span><span style="color: #0000ff;">function</span> select_database(<span style="color: #800080;">$dbname</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id->select_db(<span style="color: #800080;">$dbname</span><span style="color: #000000;">);
    }

    </span><span style="color: #0000ff;">function</span> set_mysql_charset(<span style="color: #800080;">$charset</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">in_array</span>(<span style="color: #008080;">strtolower</span>(<span style="color: #800080;">$charset</span>), <span style="color: #0000ff;">array</span>('gbk', 'big5', 'utf-8', 'utf8'<span style="color: #000000;">)))
        {
            </span><span style="color: #800080;">$charset</span> = <span style="color: #008080;">str_replace</span>('-', '', <span style="color: #800080;">$charset</span><span style="color: #000000;">);
        }
        </span><span style="color: #800080;">$this</span>->link_id->set_charset(<span style="color: #800080;">$charset</span><span style="color: #000000;">);
    }

    </span><span style="color: #0000ff;">function</span> fetch_array(<span style="color: #800080;">$query</span>, <span style="color: #800080;">$result_type</span> =<span style="color: #000000;"> MYSQLI_ASSOC)
    {
        </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$query</span>->fetch_array(<span style="color: #800080;">$result_type</span><span style="color: #000000;">);
        </span><span style="color: #800080;">$query</span>-><span style="color: #000000;">free();
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$row</span><span style="color: #000000;">;
    }

    </span><span style="color: #0000ff;">function</span> query(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$type</span> = ''<span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->link_id === <span style="color: #0000ff;">NULL</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->connect(<span style="color: #800080;">$this</span>->settings['dbhost'], <span style="color: #800080;">$this</span>->settings['dbuser'], <span style="color: #800080;">$this</span>->settings['dbpw'], <span style="color: #800080;">$this</span>->settings['dbname'], <span style="color: #800080;">$this</span>->settings['charset'], <span style="color: #800080;">$this</span>->settings['pconnect'<span style="color: #000000;">]);
            </span><span style="color: #800080;">$this</span>->settings = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
        }

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->queryCount++ )
        {
            <span style="color: #800080;">$this</span>->queryLog[] = <span style="color: #800080;">$sql</span><span style="color: #000000;">;
        }
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->queryTime == ''<span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #ff00ff;">PHP_VERSION</span> >= '5.0.0'<span style="color: #000000;">)
            {
                </span><span style="color: #800080;">$this</span>->queryTime = <span style="color: #008080;">microtime</span>(<span style="color: #0000ff;">true</span><span style="color: #000000;">);
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
            {
                </span><span style="color: #800080;">$this</span>->queryTime = <span style="color: #008080;">microtime</span><span style="color: #000000;">();
            }
        }

        </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 当当前的时间大于类初始化时间的时候,自动执行 ping 这个自动重新连接操作 </span><span style="color: #008000;">*/</span>
        <span style="color: #0000ff;">if</span> (<span style="color: #008080;">time</span>() > <span style="color: #800080;">$this</span>->starttime + 1<span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">ping();
        }

        </span><span style="color: #0000ff;">if</span> (!(<span style="color: #800080;">$query</span> = <span style="color: #800080;">$this</span>->link_id->query(<span style="color: #800080;">$sql</span>)) && <span style="color: #800080;">$type</span> != 'SILENT'<span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->error_message[]['message'] = 'MySQL Query Error'<span style="color: #000000;">;
            </span><span style="color: #800080;">$this</span>->error_message[]['sql'] = <span style="color: #800080;">$sql</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$this</span>->error_message[]['error'] = <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">error;
            </span><span style="color: #800080;">$this</span>->error_message[]['errno'] = <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">errno;

            </span><span style="color: #800080;">$this</span>-><span style="color: #000000;">ErrorMsg();

            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
        }

        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">defined</span>('DEBUG_MODE') && (DEBUG_MODE & 8) == 8<span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$logfilename</span> = <span style="color: #800080;">$this</span>->root_path . DATA_DIR . '/mysql_query_' . <span style="color: #800080;">$this</span>->dbhash . '_' . <span style="color: #008080;">date</span>('Y_m_d') . '.log'<span style="color: #000000;">;
            </span><span style="color: #800080;">$str</span> = <span style="color: #800080;">$sql</span> . "\n\n"<span style="color: #000000;">;

            </span><span style="color: #0000ff;">if</span> (<span style="color: #ff00ff;">PHP_VERSION</span> >= '5.0'<span style="color: #000000;">)
            {
                </span><span style="color: #008080;">file_put_contents</span>(<span style="color: #800080;">$logfilename</span>, <span style="color: #800080;">$str</span>,<span style="color: #000000;"> FILE_APPEND);
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
            {
                </span><span style="color: #800080;">$fp</span> = @<span style="color: #008080;">fopen</span>(<span style="color: #800080;">$logfilename</span>, 'ab+'<span style="color: #000000;">);
                </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$fp</span><span style="color: #000000;">)
                {
                    </span><span style="color: #008080;">fwrite</span>(<span style="color: #800080;">$fp</span>, <span style="color: #800080;">$str</span><span style="color: #000000;">);
                    </span><span style="color: #008080;">fclose</span>(<span style="color: #800080;">$fp</span><span style="color: #000000;">);
                }
            }
        }

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span><span style="color: #000000;">;
    }

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> affected_rows()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">affected_rows;
    }

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> error()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">error;
    }

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> errno()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">errno;
    }

    </span><span style="color: #0000ff;">function</span> result(<span style="color: #800080;">$query</span>, <span style="color: #800080;">$row</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$query</span>->data_seek(<span style="color: #800080;">$row</span><span style="color: #000000;">);
        </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$query</span>-><span style="color: #000000;">fetch_row();
        </span><span style="color: #800080;">$query</span>-><span style="color: #000000;">free();
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;
    }

    </span><span style="color: #0000ff;">function</span> num_rows(<span style="color: #800080;">$query</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">num_rows;
    }

    </span><span style="color: #0000ff;">function</span> num_fields(<span style="color: #800080;">$query</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">field_count;
    }

    </span><span style="color: #0000ff;">function</span> free_result(<span style="color: #800080;">$query</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">free();
    }

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> insert_id()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">insert_id;
    }

    </span><span style="color: #0000ff;">function</span> fetchRow(<span style="color: #800080;">$query</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">fetch_assoc();
    }

    </span><span style="color: #0000ff;">function</span> fetch_fields(<span style="color: #800080;">$query</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$query</span>-><span style="color: #000000;">fetch_field();
    }

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> version()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">version;
    }

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> ping()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">ping();
    }

    </span><span style="color: #0000ff;">function</span> escape_string(<span style="color: #800080;">$unescaped_string</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id->real_escape_string(<span style="color: #800080;">$unescaped_string</span><span style="color: #000000;">);
    }

    </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> close()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->link_id-><span style="color: #000000;">close();
    }

    </span><span style="color: #0000ff;">function</span> ErrorMsg(<span style="color: #800080;">$message</span> = '', <span style="color: #800080;">$sql</span> = ''<span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$message</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">echo</span> "<b>DTXB info</b>: <span style="color: #800080;">$message</span>\n\n<br><br>"<span style="color: #000000;">;
            </span><span style="color: #008000;">//</span><span style="color: #008000;">print('<a href="http://faq.comsenz.com/?type=mysql&dberrno=2003&dberror=Can%27t%20connect%20to%20MySQL%20server%20on" target="_blank">http://faq.comsenz.com/</a>');</span>
<span style="color: #000000;">        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">echo</span> "<b>MySQL server error report:"<span style="color: #000000;">;
            </span><span style="color: #008080;">print_r</span>(<span style="color: #800080;">$this</span>-><span style="color: #000000;">error_message);
            </span><span style="color: #008000;">//</span><span style="color: #008000;">echo "<br><br><a href="http://faq.comsenz.com/?type=mysql&dberrno=%22%20.%20%24this->error_message%5B3%5D%5B" errno . urlencode>error_message[2]['error']) . "' target='_blank'>http://faq.comsenz.com/</a>";</span>
<span style="color: #000000;">        }

        </span><span style="color: #0000ff;">exit</span><span style="color: #000000;">;
    }

</span><span style="color: #008000;">/*</span><span style="color: #008000;"> 仿真 Adodb 函数 </span><span style="color: #008000;">*/</span>
    <span style="color: #0000ff;">function</span> selectLimit(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$num</span>, <span style="color: #800080;">$start</span> = 0<span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$start</span> == 0<span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$sql</span> .= ' LIMIT ' . <span style="color: #800080;">$num</span><span style="color: #000000;">;
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$sql</span> .= ' LIMIT ' . <span style="color: #800080;">$start</span> . ', ' . <span style="color: #800080;">$num</span><span style="color: #000000;">;
        }

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);
    }

    </span><span style="color: #0000ff;">function</span> getOne(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$limited</span> = <span style="color: #0000ff;">false</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$limited</span> == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$sql</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$sql</span> . ' LIMIT 1'<span style="color: #000000;">);
        }

        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$row</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_row();
            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();
            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$row</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$row</span>[0<span style="color: #000000;">];
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
            {
                </span><span style="color: #0000ff;">return</span> ''<span style="color: #000000;">;
            }
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
        }
    }

    </span><span style="color: #0000ff;">function</span> getOneCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$sql</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$sql</span> . ' LIMIT 1'<span style="color: #000000;">);

        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;
        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getOne(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];
            }
        }

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getOne(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);
        }

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;
    }

    </span><span style="color: #0000ff;">function</span> getAll(<span style="color: #800080;">$sql</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_all(MYSQLI_ASSOC);
            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();
             </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
        }
    }

    </span><span style="color: #0000ff;">function</span> getAllCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;
        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getAll(<span style="color: #800080;">$sql</span><span style="color: #000000;">);
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];
            }
        }

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getAll(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);
        }

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;
    }

    </span><span style="color: #0000ff;">function</span> getRow(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$limited</span> = <span style="color: #0000ff;">false</span><span style="color: #000000;">)
    {
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$limited</span> == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$sql</span> = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$sql</span> . ' LIMIT 1'<span style="color: #000000;">);
        }

        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_assoc();
            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span><span style="color: #000000;">;
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
        }
    }

    </span><span style="color: #0000ff;">function</span> getRowCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;
        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getRow(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];
            }
        }

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getRow(<span style="color: #800080;">$sql</span>, <span style="color: #0000ff;">true</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);
        }

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;
    }

    </span><span style="color: #0000ff;">function</span> getCol(<span style="color: #800080;">$sql</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$res</span> = <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$res</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$arr</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
            </span><span style="color: #0000ff;">while</span> (<span style="color: #800080;">$row</span> = <span style="color: #800080;">$res</span>-><span style="color: #000000;">fetch_row())
            {
                </span><span style="color: #800080;">$arr</span>[] = <span style="color: #800080;">$row</span>[0<span style="color: #000000;">];
            }
            </span><span style="color: #800080;">$res</span>-><span style="color: #000000;">free();
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
        }
    }

    </span><span style="color: #0000ff;">function</span> getColCached(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span> = 'FILEFIRST'<span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$cachefirst</span> = (<span style="color: #800080;">$cached</span> == 'FILEFIRST' || (<span style="color: #800080;">$cached</span> == 'MYSQLFIRST' && <span style="color: #800080;">$this</span>->platform != 'WINDOWS')) && <span style="color: #800080;">$this</span>-><span style="color: #000000;">max_cache_time;
        </span><span style="color: #0000ff;">if</span> (!<span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->getCol(<span style="color: #800080;">$sql</span><span style="color: #000000;">);
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getSqlCacheData(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$cached</span><span style="color: #000000;">);
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$result</span>['storecache']) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['data'<span style="color: #000000;">];
            }
        }

        </span><span style="color: #800080;">$arr</span> = <span style="color: #800080;">$this</span>->getCol(<span style="color: #800080;">$sql</span><span style="color: #000000;">);

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$arr</span> !== <span style="color: #0000ff;">false</span> && <span style="color: #800080;">$cachefirst</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$this</span>->setSqlCacheData(<span style="color: #800080;">$result</span>, <span style="color: #800080;">$arr</span><span style="color: #000000;">);
        }

        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$arr</span><span style="color: #000000;">;
    }

    </span><span style="color: #0000ff;">function</span> autoExecute(<span style="color: #800080;">$table</span>, <span style="color: #800080;">$field_values</span>, <span style="color: #800080;">$mode</span> = 'INSERT', <span style="color: #800080;">$where</span> = '', <span style="color: #800080;">$querymode</span> = ''<span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$field_names</span> = <span style="color: #800080;">$this</span>->getCol('DESC ' . <span style="color: #800080;">$table</span><span style="color: #000000;">);

        </span><span style="color: #800080;">$sql</span> = ''<span style="color: #000000;">;
        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$mode</span> == 'INSERT'<span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$fields</span> = <span style="color: #800080;">$values</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
            </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_names</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$value</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$fields</span>[] = <span style="color: #800080;">$value</span><span style="color: #000000;">;
                    </span><span style="color: #800080;">$values</span>[] = "'" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;
                }
            }

            </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">))
            {
                </span><span style="color: #800080;">$sql</span> = 'INSERT INTO ' . <span style="color: #800080;">$table</span> . ' (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$fields</span>) . ') VALUES (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$values</span>) . ')'<span style="color: #000000;">;
            }
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #800080;">$sets</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
            </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_names</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$value</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
                {
                    </span><span style="color: #800080;">$sets</span>[] = <span style="color: #800080;">$value</span> . " = '" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;
                }
            }

            </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$sets</span><span style="color: #000000;">))
            {
                </span><span style="color: #800080;">$sql</span> = 'UPDATE ' . <span style="color: #800080;">$table</span> . ' SET ' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$sets</span>) . ' WHERE ' . <span style="color: #800080;">$where</span><span style="color: #000000;">;
            }
        }

        </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$sql</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>->query(<span style="color: #800080;">$sql</span>, <span style="color: #800080;">$querymode</span><span style="color: #000000;">);
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;
        }
    }

    </span><span style="color: #0000ff;">function</span> autoReplace(<span style="color: #800080;">$table</span>, <span style="color: #800080;">$field_values</span>, <span style="color: #800080;">$update_values</span>, <span style="color: #800080;">$where</span> = '', <span style="color: #800080;">$querymode</span> = ''<span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$field_descs</span> = <span style="color: #800080;">$this</span>->getAll('DESC ' . <span style="color: #800080;">$table</span><span style="color: #000000;">);

        </span><span style="color: #800080;">$primary_keys</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_descs</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)
        {
            </span><span style="color: #800080;">$field_names</span>[] = <span style="color: #800080;">$value</span>['Field'<span style="color: #000000;">];
            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$value</span>['Key'] == 'PRI'<span style="color: #000000;">)
            {
                </span><span style="color: #800080;">$primary_keys</span>[] = <span style="color: #800080;">$value</span>['Field'<span style="color: #000000;">];
            }
        }

        </span><span style="color: #800080;">$fields</span> = <span style="color: #800080;">$values</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$field_names</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$value</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
            {
                </span><span style="color: #800080;">$fields</span>[] = <span style="color: #800080;">$value</span><span style="color: #000000;">;
                </span><span style="color: #800080;">$values</span>[] = "'" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;
            }
        }

        </span><span style="color: #800080;">$sets</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
        </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$update_values</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$key</span> => <span style="color: #800080;">$value</span><span style="color: #000000;">)
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">array_key_exists</span>(<span style="color: #800080;">$key</span>, <span style="color: #800080;">$field_values</span>) == <span style="color: #0000ff;">true</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">is_int</span>(<span style="color: #800080;">$value</span>) || <span style="color: #008080;">is_float</span>(<span style="color: #800080;">$value</span><span style="color: #000000;">))
                {
                    </span><span style="color: #800080;">$sets</span>[] = <span style="color: #800080;">$key</span> . ' = ' . <span style="color: #800080;">$key</span> . ' + ' . <span style="color: #800080;">$value</span><span style="color: #000000;">;
                }
                </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
                {
                    </span><span style="color: #800080;">$sets</span>[] = <span style="color: #800080;">$key</span> . " = '" . <span style="color: #800080;">$value</span> . "'"<span style="color: #000000;">;
                }
            }
        }

        </span><span style="color: #800080;">$sql</span> = ''<span style="color: #000000;">;
        </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$primary_keys</span><span style="color: #000000;">))
        {
            </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">))
            {
                </span><span style="color: #800080;">$sql</span> = 'INSERT INTO ' . <span style="color: #800080;">$table</span> . ' (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$fields</span>) . ') VALUES (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$values</span>) . ')'<span style="color: #000000;">;
            }
        }
        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$this</span>->version() >= '4.1'<span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">))
                {
                    </span><span style="color: #800080;">$sql</span> = 'INSERT INTO ' . <span style="color: #800080;">$table</span> . ' (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$fields</span>) . ') VALUES (' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$values</span>) . ')'<span style="color: #000000;">;
                    </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$sets</span><span style="color: #000000;">))
                    {
                        </span><span style="color: #800080;">$sql</span> .=  'ON DUPLICATE KEY UPDATE ' . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$sets</span><span style="color: #000000;">);
                    }
                }
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
            {
                </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$where</span><span style="color: #000000;">))
                {
                    </span><span style="color: #800080;">$where</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();
                    </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$primary_keys</span> <span style="color: #0000ff;">AS</span> <span style="color: #800080;">$value</span><span style="color: #000000;">)
                    {
                        </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">is_numeric</span>(<span style="color: #800080;">$value</span><span style="color: #000000;">))
                        {
                            </span><span style="color: #800080;">$where</span>[] = <span style="color: #800080;">$value</span> . ' = ' . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span><span style="color: #000000;">];
                        }
                        </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
                        {
                            </span><span style="color: #800080;">$where</span>[] = <span style="color: #800080;">$value</span> . " = '" . <span style="color: #800080;">$field_values</span>[<span style="color: #800080;">$value</span>] . "'"<span style="color: #000000;">;
                        }
                    }
                    </span><span style="color: #800080;">$where</span> = <span style="color: #008080;">implode</span>(' AND ', <span style="color: #800080;">$where</span><span style="color: #000000;">);
                }

                </span><span style="color: #0000ff;">if</span> (<span style="color: #800080;">$where</span> && (!<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$sets</span>) || !<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$fields</span><span style="color: #000000;">)))
                {
                    </span><span style="color: #0000ff;">if</span> (<span style="color: #008080;">intval</span>(<span style="color: #800080;">$this</span>->getOne("SELECT COUNT(*) FROM <span style="color: #800080;">$table</span> WHERE <span style="color: #800080;">$where</span>")) > 0<span style="color: #000000;">)
                    {
                        </span><span style="color: #0000ff;">if</span> (!<span style="color: #0000ff;">empty</span>(<span style="color: #8"></span></b>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。