Recently, a project was developed using ThinkPHP3.1, and since the project needs to connect multiple different databases, the following configuration method is used:
1<?PHP2 return Array(3 //' Config item ' = ' config value '4 //Database configuration5' Db_prefix ' = ',6' DB_BLACK_FP ' =Array(7' Db_type ' = ' mysql ',8' Db_user ' = ' xxx ',9' db_pwd ' = ' xxx ',Ten' Db_host ' = ' xxx ', One' Db_port ' = 3306, A' Db_charset ' = ' UTF8 ', -), -' Db_black_sample ' =Array( the' Db_type ' = ' mysql ', -' Db_user ' = ' xxx ', -' db_pwd ' = ' xxx ', -' Db_host ' = ' xxx ', +' Db_port ' = 3306, -' Db_charset ' = ' UTF8 ', +), A //Other Configurations ... at);
As a practical development, it is found that the call xxxxx (YY);) will cause the database connection to be closed and subsequent database requests to fail.
It was found that using PHP's MySQL extension function to call a stored procedure does cause subsequent database requests to fail, and the workaround is to call the stored procedure once and then mysql_close the connection again.
When you debug the ThinkPHP3.1 code and discover the default single database configuration, the code logic automatically re-initiates the database connection after the call statement is executed (that is, the stored procedure is called), but not when the multi-database connection occurs.
Here's how to fix it:
1. Use mysqli instead of MySQL instead
// Other configurations... ' Db_type ' = ' mysqli ',// other configurations ...
2. Modify the Framework code:
Open frame code thinkphp3.1/lib/driver/db/dbmysqli.class.php around line 90th
// other code ...//from $res-Free_result (); // modified to if (is_object($res)) { $res, Free_result ();} // other code ...
3. Request the Framework cache:
Clear Runtime Folder Contents
Run after the above modification, calling the stored procedure no longer causes subsequent SQL execution to fail, everything is fine.
Summarize:
In fact, the MySQL extension of PHP is to support stored procedure calls, but only support no return output of the stored procedure, if the call has a return result output of the stored procedure, the next time the query statement execution, because the last stored procedure output is not read and not released, and caused an error, Therefore, subsequent query execution failures are caused.
The workaround is either to use the PDO or mysqli extension instead, or to re-initiate the database connection after each call to the stored procedure.
ThinkPHP3.1 stored procedure call bug fix under multi-database connection