I am doing a long poll and so I want to shut off my connection to the database on every loop (about 1 minute loops).
I used to use mysql_close($con), so what do I use in PDO?
Also, when I was using mysql_query it seemed to return numbers as string, so when I returned them to my calling js via json it was still a string. But now, the PDO seems to actually return it as a number. Is this right?
$db = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
// use the connection here
...........
// and now we're done; close it
unset($db);
After a successful connection to the database, an instance of the PDO class is returned to your script. The connection remains active for the lifetime of that PDO object. To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted--you do this by assigning NULL to the variable that holds the object. If you don't do this explicitly, PHP will automatically close the connection when your script ends.
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
//just unset the variable:
unset($dbh);
//or
$dbh = null;