php uses pdo method to close the database: [$conn = null;]. If you want to connect to the database, the method is [$conn = new PDO("mysql:host=$server;dbname=mysql", $user, $password)].
Implementation code:
(Recommended tutorial:php video tutorial)
你所连接的服务器地址:".$servername; echo "
Output:
try { //...} catch(Exception $e) { //...}
try{}catch{} in PHP is exception handling
Put the code to be executed into the TRY block. If there is a problem during the execution of these codes, If an exception occurs in a statement, the program jumps directly to the CATCH block, and $e collects error information and displays it.
If an exception is thrown, the script in the try statement will stop executing and then immediately redirect Execute the script in the catch statement.
If an exception is thrown but is not caught, a fatal error will be generated.
Related recommendations:php training
The above is the detailed content of How to use pdo to close the database in php. For more information, please follow other related articles on the PHP Chinese website!