thinkphp 数据库3.1怎么都连不上mysql数据库 请大虾帮忙

当前位置:
在结果中搜索
文件名称:Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体
所属分类:
资源属性:
Linux,其它,PHP,其它
上传时间:
文件大小:
浏览/下载:
846次 / 1次
提 供 者:
相关连接:
下载说明:
别用迅雷下载,失败请重下,重下不扣分!
相关搜索:
(系统自动生成,下载前可以参看下载内容)下载文件列表
压缩包 : Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体).rar 列表
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Css/common.css
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Css/index.css
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Css/list.css
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Css/show.css
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/content-title.png
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/list.gif
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/logo-bottom.gif
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/logo.ico
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/logo.png
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/nav-bg.gif
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/nav-sep.gif
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/other-title.png
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images/search-form.gif
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/index.html
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Js/common.js
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Js/jquery-1.7.2.min.js
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/list.html
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/show.html
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/font.ttf
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Image.class.php
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Css
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Images
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog/Js
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)/Blog
后盾网Thinkphp3.1.3视频教程资料(BLog模板_图片类_字体)
暂无评论内容.
*主  题:
*内  容:
*验 证 码:
资源属性分别代表:系统平台,开发平台,开发语言,文件格式四部分.
请用浏览器直接下载本站软件,用进行解压.
请使用单线程下载,否则可能会被扣除(线程数*积分).
如果您发现此软件无法下载,请稍后再次尝试;或者.
本软件为网上收集或会员上传,若无意中侵犯了您的版权,.
如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
如下载后发现下载的东东跟说明不相乎,可以联系本站的客服,经确认可以退回消费了的积分.
源码中国 www.ymcn.org
All Rights Reserved.Language Selection
eCommerce & Portal Experts!
Latest News:
The multi-database connection table prefix isolation in ThinkPHP 3.1 version
Company Blog
背景概述:我现在有三个数据库,分别在不同的机子上面。表前缀各不相同。暂且将这三个数据库进行编号为:A、B、C。A数据库我使用了 config.php常规的PDO配置方式,B、C我使用了DB_CONFIG这种配置方式。当我在Model类里面进行protected $connection受保存变量进行配置的时候,如:
protected $connection = 'DB_CONFIG1';在分别实例化A、B、C的时候,出现了一个大大的问题。A的表前缀,不管任何时候都会影响B、C的。哪怕,B、C设置或不设置表前缀都是如此。
以下是我遇到问题之后的解决方法,同时也把此问题提交到了官方的论坛BUG版块。
官方这个BUG直接影响了多库操作用户,希望即时恢复。通过两个小时的调试,附上我的解决方案,希望官方也能从中得到BUG症结所在:
解决思路如下:
1、在Db.class.php脚本文件里面的类增加一个魔术方法__get(),写法如下:
public function __get($propertyName)
{ return $this-&$propertyN
这个方法是用来访问类中protected $config成员属性用的。有的人可能会说,直接把protected改成public岂不是更好。这样只解决了基类的问题,假如,子类也同样进行了受保护,那要你更改更多的文件,这是我们做IT程序员非常不愿意看到的事情。
2、在Model.class.php中的getTableName()方法更改如下:
$tablepre = $this-&db-&config['tablepre'];
if(empty($this-&trueTableName)) {
$tableName??= empty($tablepre) ? $this-&tablePrefix : $
if(!empty($this-&tableName)) {
$tableName .= $this-&tableN
$tableName .= parse_name($this-&name);
$this-&trueTableName? ? =? ?strtolower($tableName);
return (!empty($this-&dbName)?$this-&dbName.'.':'').$this-&
trueTableN这样就完成了多库自由切换时,导致的表前缀问题。
/*******************面向对象PDO连接方式*********************/
'DB_TYPE' =& 'PDO', // 数据库类型
'DB_DSN' =& 'mysql:host=dbname=master', // DSN连接。
'DB_USER' =& 'root', // 数据库用户名
'DB_PWD' =& ';, // 数据库密码
'DB_PORT' =& '3306', // 数据库端口
'DB_PREFIX' =& 'g_', // 数据表前缀
'DB_CHARSET' =& 'utf8', // 数据库编码默认采用utf8
可能很多朋友,没有遇到这种情况过。因为,很少接触多库操作。现在给出解决方案,
望官方下次提交BUG时能修复,我在这里,一直等待官方的回应。
以上的解决方法固然能解决问题,但是,却有很多的不足,不足之处是要改框架的核心代码。最后经过ThinkPHP官方的回答,我了解到是我自己对问题了解不足所导致的问题。
官方并没有承认这是一个BUG,所以,他们的解决方法是:
创建一个表的Model模型的时候,在模型类里面设置受保护的成员属性$tablePrefix的值为当前表的表前缀。这个方法完全解决了我遇到的问题。
现在我们来思考一下官方的做法。既然官方提供了配置文件直接读取的方法,通过受保护的属性$connection ,那么,我在配置里面的表前缀就应该得到支持。然后,在多库切换的时候,ThinkPHP框架却忽略了这个问题。既然,官方不承认这是一个BUG的话,那么,我们就按照官方的处理办法吧。其实只是要注意这个问题的存在,免得像我一样在这里纠结了半天。最后,搞出一个非官方的解决办法。
Published in
Latest from Li Pingping
Portfolios
Technical Competence
News & Blog
Founded in 2009, EveBit Digital, a CMMI3 Certified Company, has grown to become one of China&s foremost eCommerce & Portal companies providing solution and development services.
As professionals, we specialize in delivering sophisticated Websites custom-designed to meet each client&s unique requirements using PHP, Magento, Joomla!, Drupal, WordPress, WeChat and Android / iOS for Internet Applications.
Under the guidance of our Certified Zend and Magento Engineers, we employ the very best web technologies available for Brand eCommerce, Cross-border eCommerce, O2O Platform, Content Management Systems (CMS) and Mobile Internet solutions.
Email: info[& Phone: +86-27-& Online Inquiry: Send your inquiry by
Magento Cases
Joomla Cases
Mobile Application Dev
Zend Framework Cases
CMS Professionals
Our team provides full levels of CMS solutions from personal blog, small firm brochure to news portal and eCommerce. We are the few company in the world, who delivered commerical projects for all the major PHP based CMS systems such as WordPress, Joomla!, TYPO3 and Drupal.
Web to Mobile solutions
Starting from PHP, cov we offer a complete suite of tools and services to build / upgrade cross-platform browsing experiences on CMS and eCommerce systems. We have helped clients deployed Joomla! and Magento based projects not only on web, but also as android and iOS applications.
Magento Professionals
We've built a reputation for expertise with , the most sophisticated eCommerce platform. We offer an end-to-end service from stunning designs to seamless integration with ERP and payment gateways. From 2012,& five of developers passed the Magento Certified Developer, which more than any company in China.
Zend Certified Professional
EveBit Digital has a large team worked with Zend Framework in a number of different contexts, such as bespoke applications and collaborated on enterprise-level projects with organisat some of our engineers passed the most authoritative Zend Certified Engineer.
Company Blog
Developers' Blog
   
Our Associations
|||Email: info[|Call us: +86-27-
武汉伊锐数码技术开发有限公司&&版权所有&&Copyright (C)
EveBit Digital&&&&&&&&&&&&All Rights Reserved.1500个ecshop项目经验,多个高率插件,完整的经验总结
&ecshop交流群:()&&
ecshop2014最新模板
价格:¥1100
价格:¥1100
价格:¥1100
价格:¥1100
价格:¥2000
价格:¥1500
thinkphp连接多个数据库
thinkphp连接多个数据库连接多数据库的方式很多,最简单的就在初始化M模型的时候,带上数据库信息参数。以下是代码。 $User = M('goods','ecs_','mysql://root:root@localhost/272utfdenglu'); $res = $Us
  &&& thinkphp连接多个数据库连接多数据库的方式很多,最简单的就在初始化M模型的时候,带上数据库信息参数。以下是代码。
&&& $User = M('goods','ecs_','mysql://root:root@localhost/272utfdenglu');
&&& $res = $User-&where(&goods_id='1'&)-&field('*')-&find();
------分隔线----------------------------
相关文章:&
ecshop热门技术
ecshop自定义目录结构伪静态url,这个功能是非常多的人想要的,其...
ecshoplinux服务器常用命令,主要是是讲述ecshop如何在linux服务器下...
最近很多使用ecshop的人都开始想办法整合qq登陆。qq联合登陆平台...
最近很忙,也没时间去打理一些资料和开发笔记,去年总结了...
1:如何修改网站欢迎光临本店 回答:languages\zh_cn\common.php文件中,...
很多人用ecshop来做B4C电子商务平台,通常都是先将程序放到服务...

我要回帖

更多关于 thinkphp 数据库 的文章

 

随机推荐