Hi,
for a project I need to open a Mysql connection, close it and let old legacy code run after that. The legacy code have it's own connection, and just call mysql_query($sql) without the resource parameter.
How can I handle this? Can I set a Mysql connexion as the global one? Must I re-execute the mysql_connect() statement? The legacy code can't be refactored just now.
Here a short demo
<?php
function show()
{
$a = mysql_fetch_array(mysql_query('select database()'));
echo $a[0] . "<br>";
}
$conn = mysql_connect('localhost', 'root', '', TRUE);
mysql_select_db('dredd');
show();
mysql_connect('localhost', 'root', '', TRUE);
mysql_select_db('afup');
show();
mysql_close();
$a = mysql_fetch_array(mysql_query('select database()', $conn));
echo $a[0] . "<br>";
show();
The first select is ok, the second two, the third is ok because it have the ressource, but the fourth broke ("Access denied for user 'ODBC'@'localhost' (using password: NO)").
Regards, Cédric