ThinkPHP跨库操作

WBOY
Release: 2016-06-06 20:35:21
Original
1121 people have browsed it

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

<code>namespace Home\Model;
use Think\Model;
class CategoryModel extends Model {
    protected $trueTableName = 'top_categories'; 
    protected $dbName = 'top';
}
</code>
Copy after login
Copy after login
<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>
Copy after login
Copy after login

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

回复内容:

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

<code>namespace Home\Model;
use Think\Model;
class CategoryModel extends Model {
    protected $trueTableName = 'top_categories'; 
    protected $dbName = 'top';
}
</code>
Copy after login
Copy after login
<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>
Copy after login
Copy after login

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

$myModel = new CategoryModel ();

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

已经解决了。
ThinkPHP跨库调用

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template