Do SQL connections opened with PDO in PHP have to be closed

后端 未结 6 1490
野的像风
野的像风 2020-11-28 07:36

When I open a MySQL connection in PHP with just PHP\'s built-in MySQL functions, I do the following:

$link = mysql_connect($servername, $username, $password)         


        
6条回答
  •  时光取名叫无心
    2020-11-28 07:43

    Well seeing as the $link for the PDO is assigned an object, PHP would set that as null as soon as the script runs so that it's no longer an object. Therefore you could just do:

    $link = new PDO("mysql:dbname=$dbname;host=$servername",$username,$password);
    
    //prepare statements, perform queries
    
    $link = null;
    

提交回复
热议问题