xiaohua1054 发表于 2012-2-2 09:44:56

DB_driver.php 中的 _protect_identifiers 函数疑问

        /**
       * Protect Identifiers
       *
       * This function is used extensively by the Active Record class, and by
       * a couple functions in this class.
       * It takes a column or table name (optionally with an alias) and inserts
       * the table prefix onto it.Some logic is necessary in order to deal with
       * column names that include the path.Consider a query like this:
       *
       * SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table
       *
       * Or a query with aliasing:
       *
       * SELECT m.member_id, m.member_name FROM members AS m
       *
       * Since the column name can include up to four segments (host, DB, table, column)
       * or also have an alias prefix, we need to do a bit of work to figure this out and
       * insert the table prefix (if it exists) in the proper position, and escape only
       * the correct identifiers.
       *
       * @access        private
       * @param        string
       * @param        bool
       * @param        mixed
       * @param        bool
       * @return        string
       */
上边是这个函数的注释

sql 语句有这样的写法吗?
SELECT * FROM hostname.database.table.column AS c FROM hostname.database.table


Hex 发表于 2012-2-2 11:50:40

当然有那样的写法了。。。。。。

xiaohua1054 发表于 2012-2-2 11:56:22

Hex 发表于 2012-2-2 11:50 static/image/common/back.gif
当然有那样的写法了。。。。。。

怎么验证这种写法的正确性呢? 向您学习一下

Hex 发表于 2012-2-2 11:57:33

xiaohua1054 发表于 2012-2-2 11:56 static/image/common/back.gif
怎么验证这种写法的正确性呢? 向您学习一下

什么是验证正确性?SQL语法就是这样的啊。
也就是跨库跨表查询。

xiaohua1054 发表于 2012-2-2 13:14:01

Hex 发表于 2012-2-2 11:57 static/image/common/back.gif
什么是验证正确性?SQL语法就是这样的啊。
也就是跨库跨表查询。

select * from database.table;

上面的sql是正确的为何我在前面加上主机名就不对了呢?
如: select * from hostname.database.table;

可以跨主机查询吗? hostname是跨主机查询时用到了吗?

Hex 发表于 2012-2-2 14:23:29

xiaohua1054 发表于 2012-2-2 13:14 static/image/common/back.gif
select * from database.table;

上面的sql是正确的为何我在前面加上主机名就不对了呢?


我知道 mssql 是可以的, mysql 没试过。由于这个代码是跨数据库的,所以这么写的。
具体你可以 google 一下相关资料。
页: [1]
查看完整版本: DB_driver.php 中的 _protect_identifiers 函数疑问