开发者

php sql error message changed database context

I have a routine that I call to do a mssql and mysql server connect like so:

$mysql_aoi_conn = DoMySQLConnect( 'AOI' );  
$mssql_aoi_conn = DoMsSQLConnect( 'itf' );

t开发者_JAVA技巧he functions are as follows:

function DoMySQLConnect( $pdb_name ){
    $mysql_conn = mysql_connect('localhost', '####', '####') or die( 'could not connect to localhost server : ' . mysql_error() );
    $mysqldb_conn = mysql_select_db( $pdb_name, $mysql_conn ) or die('could not use database ' . $pdb_name . ' : ' . mysql_error() );   
    return array("database" => $mysqldb_conn, "connection" => $mysql_conn );
};
function DoMsSQLConnect( $pdb_name ){
    $mssql_conn = mssql_connect("128.251.xxx.xxx", '###', '###') or die("failed to connect to server USLONSAPP003");
    $mssqldb_conn = mssql_select_db( $pdb_name, $mssql_conn) or die("failed to select database " . $pdb_name);
    return array("database" => $mssqldb_conn, "connection" => $mssql_conn );
};

I'm trying to use the connection implementation within the mssql_query and mysql_query to tell my queries which connection to use but I'm getting an error. Here is one of my queries:

$login_res = mssql_query("SELECT *
                          FROM ITF_USER
                          WHERE ITF_LOGIN = '" . $lcUserName . "'", $mssql_aoi_conn['connection'] )
                          or die("failed to query ITF_USER: \n" . mssql_get_last_message() );

This dies with the mssql_get_last_message() of: Changed database context to 'itf'. which is not really an error. Can someone tell me if I'm utilizing this query option wrong?


After some research it seems that mssql_query() doesn't support the link_identifier option and therefore breaks (albeit without a valid error for debugging). Removing the link identifier for the mssql_query and keeping it throughout my document for any mysql_query() lets me use both mssql_query() and mysql_query() commands throughout my script.


Even though you have solved your problem, I was facing a similar error "changed database context" when using the mssql_exec() function in PHP. It seems to be fixed by setting:

sqlsrv_configure ( "WarningsReturnAsErrors" , 0 ); //OFF
sqlsrv_configure ( "LogSeverity" , 1 ); //SQLSRV_LOG_SEVERITY_ERROR

Before that, I was using [DATABASE].[dbo].[TABLE] to prevent getting lots of reports about such error/warning.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜