Calling mysql_query()
without a connection parameter will use the most recently established connection. So as long as you're only connecting to one database, you won't see any problems.
From the docs:
If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If no connection is found or established, an E_WARNING level error is generated.
If you add or include some new code that's connecting to a different database though - perhaps a hit tracker, or an analytics tool, for example - then that can break your existing code because it establishes another mysql connection - and any of your queries that happen after that new connection is established will now be using the wrong connection.
This will happen even if the extra code is properly written and always uses its own connection identifier - it won't have problems of accidentally using your connection, but your code will still accidentally use its connection.
To safely use mysql_query()
, you really need to keep track of the database connection, and use it in every query.
All that being said - if you're making changes to all the mysql_*
calls anyways, please consider switching to mysqli
. The mysql_*
functions are deprecated and no longer supported. The mysqli
extension can be almost a drop-in replacement, and also provides support for features such as prepared statements.
The PDO extension is another possible replacement, but would require a bit more rewriting when switching from using mysql_*
.