为什么从Codeigniter 3.0 PHP连接时,所有会话的SQL Server @@ spid都相同?
我已成功从Codeigniter 3.0.2连接到SQL Server。我正在使用sqlserv驱动程序。 为什么SQL Server @@ spid总是为不同的用户会话返回相同的内容 我的数据库连接未设置为Persist。 我怎么能让它不坚持。这是我的数据库连接。
$db['default'] = array(
'dsn' => '',
'hostname' => '127.0.0.1',
'username' => 'user',
'password' => 'password',
'database' => 'Testdb',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
我从codeigniter尝试了同样的Mysql Connection。它按预期工作非持久性。 ?
答案 0 :(得分:0)
参考以下链接, https://msdn.microsoft.com/en-us/library/cc644930%28SQL.90%29.aspx
连接池(适用于SQL Server的PHP的Microsoft驱动程序)
以下是有关SQL驱动程序的PHP驱动程序中的连接池的重要注意事项:
The Microsoft Drivers for PHP for SQL Server uses ODBC connection pooling.
By default, connection pooling is enabled. When you connect to a server, the driver attempts to use a pooled connection before it creates a new one. If an equivalent connection is not found in the pool, a new connection is created and added to the pool. The driver determines whether connections are equivalent based on a comparison of connection strings.
When a connection from the pool is used, the connection state is reset.
Closing the connection returns the connection to the pool.
我可以通过设置
解决问题$db['default'] = array(
'dsn' => '',
'hostname' => '127.0.0.1',
'username' => 'user',
'password' => 'password',
'database' => 'Testdb',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
当我设置pconnect'=>是,'app_id'=>''。rand()在连接期间, 新的@@ SPID已创建。
因此,通过有效地设置'app_id',可以控制应用程序或用户组或用户的池化
警告:通过设置pconnect'=>是的,'app_id'=>''。rand(),您实际上是在使应用程序中的连接池效果无效。 建议小心使用。