TP升级到3.2.3的注意事项

从TP3.2.2升级到3.2.3有以下几点需要注意
1 TP3.2.3的DB FIELD默认小写,如果DB有大小写混合的设计,需要在config.php添加以下设置
'DB_PARAMS'    =>    array(\PDO::ATTR_CASE => \PDO::CASE_NATURAL),

2 'URL_CASE_INSENSITIVE' =>true時,APP_DEBUG=true,若Action名或模板名帶有大小寫,會出現找不到模板的異常,因此'URL_CASE_INSENSITIVE' 一律設置為false(默認值)

3 APP_DEBUG設置在index.php,config.php不需要再設置

4 3.2.2的ThinkPHP\Library\Think\Log\Driver\File.class.php 有bug。若在Runtime下没有对应module的目录,则\Think\Log::write()无法创建目录并生成log文件。3.2.3 fixed这个问题了。

5 第三方類庫建议存放位置\ThinkPHP\Library\Vendor

6 join的默认类型由left join 改成了inner join

...

7 3.2對sql語句檢查更加嚴格。若DB Field設置為not null,而sql將該值設置為null,則sql會拋出異常。若某個not null字段為null,而其它字段正常的情況下,TP3.2會將not null的字段對應的語句過濾掉
demo 1:

public function testUpdate()
	{
		$data['HKID'] = null;
		$searchData['user_id'] = 3;
		$result = D("OauthUser")->where($searchData)->save($data);
		echo $result!==false ? "success" : "failed";
		echo " " . D("OauthUser")->getLastSql();
	}

HKID字段在DB是not null,若設置為null,會拋出以下異常
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `user_id` = 3' at line 1
改成$data['HKID'] = ""; 執行成功

demo 2:
public function testMultiUpdate()
	{
		$data['HKID'] = null;
 $data['districtID'] = 1;
		$searchData['user_id'] = 3;
		$result = D("OauthUser")->where($searchData)->save($data);
		echo $result!==false ? "success" : "failed";
		echo " " . D("OauthUser")->getLastSql();
	}


以上更新不會拋出異常。生成的sql會過濾掉不符合DB的HKID字段。生成的SQL:
UPDATE `oauth_users` SET `districtID`='1' WHERE `user_id` = 3



你可能感兴趣的:(thinkphp)