0

I have a site in a server, and the data base in other server.

My site was connected with two differnt data bases at the same time without any problem, but when I change the server's data base I had a problem, my site did not recognice two conecctions.

The solution that i found was, set true on the parameter "new link" in mysql_connect function, as the same:

$link_web = mysql_connect($host_web,$user_web,$pass_web, true)

But i have a question about other possible solution.

Could i solve the problem, setted sql.safe-mode as 'on' in my php.ini? or is possible solve this problem whiht another way without change the source code?

  • ___but when I change the server's data base I had a problem___ Sounds like we need to know what you changed then, as this seems a likely reason for the issue – RiggsFolly Feb 23 '21 at 18:13
  • 2
    The `mysql_` functions have been obsolete for nearly 10 years. They are no longer supported. If you're running them successfully you must also be running an unsupported version of PHP, because they were removed when PHP 7 was launched. You should be using mysqli or PDO. Make a plan to upgrade, urgently. – ADyson Feb 23 '21 at 18:25
  • the last version of mysql was MySQL 5.5.50, and now the new server have MariaDB 10.5.6 – Vanessa Marchelli Feb 23 '21 at 18:25
  • But what version of PHP are you now running – RiggsFolly Feb 23 '21 at 18:26
  • thanks ADyson for the advice, if we are thinking of updating – Vanessa Marchelli Feb 23 '21 at 18:26
  • Anyway "did not recognise" is a bit vague. Show the code for making the two connections and explain the exact error you're experiencing – ADyson Feb 23 '21 at 18:28
  • My PHP version is 5.6.35 – Vanessa Marchelli Feb 23 '21 at 18:29
  • https://www.php.net/supported-versions.php shows what versions of PHP you can upgrade to so you're running a supported, secure version – ADyson Feb 23 '21 at 18:32

1 Answers1

1

There are lots of ways you could fool PHP into creating separate connections - but they are, at best, redundant. You are relying on facts about your data access (the database you are connecting to) persisting in the database session. That's not a good starting point for writing large, complex applications where you cannot always be certain of the sequence of events. A neater solution is to still call mysql_connect() twice (in case the databases are ever split across separate hosts) have your code treat the returned handles as 2 seperate values and specify in your sql what database the DML applies to:

SELECT *
FROM yourdatabase.yourtable;
symcbean
  • 47,736
  • 6
  • 59
  • 94