Home  >  Article  >  Backend Development  >  ThinkPHP跨库操作

ThinkPHP跨库操作

WBOY
WBOYOriginal
2016-06-06 20:35:211115browse

Thinkphp操作当前数据库以外的数据表时,发现更新字段的时候返回0,是跨库就不没有写入权限了么?

<code>namespace Home\Model;
use Think\Model;
class CategoryModel extends Model {
    protected $trueTableName = 'top_categories'; 
    protected $dbName = 'top';
}
</code>
<code>$myModel = new CategoryModel ();
//ID为主键
$data = array('num'=>1,'id '=> 1);
$status = $myModel->save($data);
//或者
$data = array('num'=>1);
$status = where(array('id'=> 1))->save($data);
</code>

返回的$status都是0,为什么?

回复内容:

Thinkphp操作当前数据库以外的数据表时,发现更新字段的时候返回0,是跨库就不没有写入权限了么?

<code>namespace Home\Model;
use Think\Model;
class CategoryModel extends Model {
    protected $trueTableName = 'top_categories'; 
    protected $dbName = 'top';
}
</code>
<code>$myModel = new CategoryModel ();
//ID为主键
$data = array('num'=>1,'id '=> 1);
$status = $myModel->save($data);
//或者
$data = array('num'=>1);
$status = where(array('id'=> 1))->save($data);
</code>

返回的$status都是0,为什么?

$myModel = new CategoryModel ();

实例化模型不是用D方法么。。。

已经解决了。
ThinkPHP跨库调用

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn