note 78187 added to function.mysql-connect

From: Date: Tue, 02 Oct 2007 13:20:27 +0000
Subject: note 78187 added to function.mysql-connect
Groups: php.notes 
Request: Send a blank email to php-notes+get-130983@lists.php.net to get a copy of this message
The use of mysql connections can become tricky with objects. I am using mysql_connect() in a database class I wrote and the class destructor calls mysql_close. Because I have several of these database objects, mysql_connect reuses existing connections. This is fine except when the script reaches the end of execution and PHP's garabage collection calls all the objects' __destruct() functions. mysql_close() throws a warning that the connection is invalid, in my case for one object. This is happening with objects which use an existing connection, as the connection has already been closed. I solved the problem by forcing mysql_connect() to create a new connection each time. This is not efficient but is sufficient for my purposes for now. I wouldn't say this is a bug per-se, but it's something to look out for. I imagine using mysqli is the ultimate solution... ---- Server IP: 85.12.26.134 Probable Submitter: 213.10.255.120 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php Edit -- https://master.php.net/note/edit/78187 Del: integrated -- https://master.php.net/note/delete/78187/integrated Del: useless -- https://master.php.net/note/delete/78187/useless Del: bad code -- https://master.php.net/note/delete/78187/bad+code Del: spam -- https://master.php.net/note/delete/78187/spam Del: non-english -- https://master.php.net/note/delete/78187/non-english Del: in docs -- https://master.php.net/note/delete/78187/in+docs Del: other reasons-- https://master.php.net/note/delete/78187 Reject -- https://master.php.net/note/reject/78187 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130983) next »