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

[HELP] mysql_connect和mysql_pconnect都废弃了?那CI里面怎么mysql?

[复制链接]
发表于 2013-4-8 20:11:12 | 显示全部楼层 |阅读模式
本帖最后由 maxint64 于 2013-4-8 20:17 编辑

今天发现自己搭的网站总是显示一个空白页面,也不报错。检查了服务器设置,没发现问题,然后从CI的代码一路查下来,在mysql_driver.php里发现了问题。
PHP复制代码
function db_connect()        {
                if ($this->port != '')
                {
                        $this->hostname .= ':'.$this->port;
                }
 
                return mysql_connect($this->hostname, $this->username, $this->password, TRUE);
        }
 
        // --------------------------------------------------------------------
 
        /**
         * Persistent database connection
         *
         * @access        private called by the base class
         * @return        resource
         */

        function db_pconnect()
        {
                if ($this->port != '')
                {
                        $this->hostname .= ':'.$this->port;
                }
 
                return mysql_pconnect($this->hostname, $this->username, $this->password);
        }
复制代码

我把db_pconnect函数里mysql_pconnect前面的@去掉,然后看到了错误信息
Fatal error: Call to undefined function mysql_pconnect()
然后试了下用db_connect,结果也报错了
Fatal error: Call to undefined function mysql_connect()
这两个函数怎么可能是undefined?跑到PHP官网一看,这两个函数的页面里都出了一个warning,
This extension is deprecated as of PHP 5.5.0
mysql_connect -> http://php.net/manual/en/function.mysql-connect.php
mysql_pconnect -> http://www.php.net/manual/en/function.mysql-pconnect.php
请问这是怎么一回事?要怎么解决?我觉得还有其它的原因,因为我的PHP版本是早于5.5的。
我的环境:ubuntu 12.10 + nginx 1.2.1 + php 5.4.9 + Codeigniter 2.1.2 + mysql 5.5.29


发表于 2013-4-9 17:19:49 | 显示全部楼层
php 没开mysql模块吧
 楼主| 发表于 2013-4-9 17:43:58 | 显示全部楼层
合合 发表于 2013-4-9 17:19
php 没开mysql模块吧

呃 确实……3Q
发表于 2015-10-21 16:48:32 | 显示全部楼层
请根据提示,用mysqli_connect代替mysql_connect,如果你会提示出错,基本是你的php和mysql版本都提升的导致的.代码用 mysqli 多一个 i
就这么简单.........

本版积分规则