cakephp 2.x选择sql服务器数据库的问题

vhipe2zx  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(142)

我在cakephp 2.x中连接sql服务器后写下面的查询。

$this->User->find('first', array('conditions' => array('User.USER_ID' => 1)));

这将生成以下查询

SELECT TOP 1 [User].[USER_ID] AS [User__USER_ID], [User].[USER_NAME] AS [User__USER_NAME]
FROM [ec_user_details] AS [User] 
WHERE [User].[USER_ID] = 1

以上查询通过以下错误

SQLSTATE[42S02]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'ec_user_details'.

如何在cakephp中通过ORM创建以下查询

SELECT TOP 1 [User].[USER_ID] AS [User__USER_ID], [User].[USER_NAME] AS [User__USER_NAME]
FROM [**DB_NAME**].[ec_user_details] AS [User] 
WHERE [User].[USER_ID] = 1

请帮帮忙

zaqlnxep

zaqlnxep1#

在花了很多时间之后,我找到了解决方案。
public $默认值=数组(

'host' => '127.0.0.1',
'login' => 'username',
'password' => 'paasword',
'database' => 'db_name',                 
'datasource' => 'Database/Sqlserver',
'persistent' => false,
'prefix' => '',
'encoding'  => PDO::SQLSRV_ENCODING_UTF8,
'schema'=>'db_name'

);

相关问题