用户
 找回密码
 入住 CI 中国社区
搜索
查看: 3224|回复: 5
收起左侧

[已解决] DB_driver.php 中的 _protect_identifiers 函数疑问

[复制链接]
发表于 2012-2-2 09:44:56 | 显示全部楼层 |阅读模式
        /**
         * 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


发表于 2012-2-2 11:50:40 | 显示全部楼层
当然有那样的写法了。。。。。。
 楼主| 发表于 2012-2-2 11:56:22 | 显示全部楼层
Hex 发表于 2012-2-2 11:50
当然有那样的写法了。。。。。。

怎么验证这种写法的正确性呢? 向您学习一下
发表于 2012-2-2 11:57:33 | 显示全部楼层
xiaohua1054 发表于 2012-2-2 11:56
怎么验证这种写法的正确性呢? 向您学习一下

什么是验证正确性?SQL语法就是这样的啊。
也就是跨库跨表查询。
 楼主| 发表于 2012-2-2 13:14:01 | 显示全部楼层
Hex 发表于 2012-2-2 11:57
什么是验证正确性?SQL语法就是这样的啊。
也就是跨库跨表查询。

select * from database.table;

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

可以跨主机查询吗? hostname是跨主机查询时用到了吗?
发表于 2012-2-2 14:23:29 | 显示全部楼层
xiaohua1054 发表于 2012-2-2 13:14
select * from database.table;

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

我知道 mssql 是可以的, mysql 没试过。由于这个代码是跨数据库的,所以这么写的。
具体你可以 google 一下相关资料。

本版积分规则