I'm the developer of a PHP comments script which is designed to be included into the body of the users' websites. The script has its own database connection and currently uses the 'MySQL' extension. To make the script easier to integrate, I preserve the website's existing database connection (if there is one) by adding these two lines before connecting to the script's own connection ..
@$original_database = mysql_query('SELECT DATABASE();');
@$original_database = mysql_result($original_database, 0);
.. then after my script has finished I select the original database ..
if (!empty($original_database)) {
@mysql_select_db ($original_database);
}
This is working fine at the moment. However many websites are (quite rightly) starting to use the newer extensions such as 'MySQLi' and 'PDO', and this makes it harder to preserve the existing database connection because for instance 'MySQLi' will complain that the connection is through 'MySQL'. Can you recommend the best way to deal with this? If it makes any difference, I plan to switch from 'MySQL' to 'MySQLi' in the near future, but obviously I will still have the same problem.