简体   繁体   English

如何在当前PHP脚本中获取所有MySQL命令?

[英]How can I get all MySQL commands in the current PHP script?

我如何获取所有在当前php脚本中已经使用过的MySQL命令?我没有使用任何框架,我尝试使用google进行搜索,但显然我没有任何帮助,请给我一些有用的建议,宽恕我的英语不好,谢谢。

From linux command line: 从linux命令行:

grep -n mysql_* [yourfile.php]

Which will give you every instance of a mysql_ command (eg mysql_connect(), mysql_close(), etc) and the line number where it was found in the file. 这将为您提供mysql_命令的每个实例(例如mysql_connect(),mysql_close()等)以及在文件中找到它的行号。 It may be useful to dump the output of this command into a file by doing the following: 通过执行以下操作,将此命令的输出转储到文件中可能会很有用:

grep -n mysql_* [yourfile.php] > mysql_commands.txt

Grep has a number of useful options for searching for a text string within a single file, a group of files, or an entire directory. Grep有许多有用的选项,可用于在单个文件,一组文件或整个目录中搜索文本字符串。 Use grep --help to see some of these options. 使用grep --help查看其中一些选项。

Without any framework, you need to make your own function to run any SQL on your page, eg: 如果没有任何框架,则需要创建自己的函数以在页面上运行任何SQL,例如:

$sql = 'select * from users limit 10';
$rows = run_sql($sql);
$sql = 'update users set male=1 where id=2';
$rows = run_sql($sql);
...

function run_sql($sql) {
    global $debug;
    if ($debug) {
        echo '<p>', htmlsepecialchars($sql), '</p>';
    }
    //do what you normally do with the SQL
}

Before php framework, there are lots of nice db functions you can get by asking google. 在使用PHP框架之前,可以通过询问google获得很多不错的数据库函数。 Nowadays not much as many people move to frameworks. 如今,迁移到框架的人并不多。

If you want an example, have a look of Topnew DB Helper, it is a function: http://topnew.net/cms/wiki/cms_db.php 如果您需要一个示例,请查看Topnew DB Helper,它是一个功能: http ://topnew.net/cms/wiki/cms_db.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM