doumi1852 2019-01-18 09:08
浏览 69

php:有没有办法从SQL字符串中获取数据库,表和字段列表?

I need to build a monitor to list all the fields, tables and database every time they are queried.

I would then like to build a script that starting from a query like this:

select
   table_a.field_1, table_a.field_2,
   table_b.field_3
from
   database_I.table_a
   database_II.table_b
where
   table_a.idx = table_b.idx

would get me this array

$objects = array(
   'database_I.table_a.field_1',
   'database_I.table_a.field_2',
   'database_II.table_b.field_3'
)

Playing with ''mysql_field_table'' and ''mysql_field_name'' I can get the table and field name but not the database_name also.

Is there any way to get it just starting from the parsing of the SQL query (altohough it would be a SELECT, INSERT INTO, UPDATE or whatelse)?

  • 写回答

0条回答 默认 最新

    报告相同问题?