0

I have installed php 7.0.15. and the project I am working on, has a php version of 5.0. How can I run php 5.0 in php 7.0.15.I have other project working on php 7.0.15. so I can't install php 5.0. Is there any way to solve this issue?

Any help would be great.

Thank You.

  • You can't. In particular when you need mysql_* functions which were specifically removed from PHP 7. – Jonnix Apr 07 '17 at 11:55
  • _"How can I run php 5.0 in php 7.0.15"_ .. ehm, you can't since they are two totally different versions? – M. Eriksson Apr 07 '17 at 11:56
  • `mysql_*` was removed on PHP 7.0. The closest you can do to solve it is to use `mysqli_*`. Or write your own `mysql_* layer`. – Ismael Miguel Apr 07 '17 at 11:56
  • I have huge amount of `mysql_*` queries. so is there any extension or something like that? –  Apr 07 '17 at 11:58
  • Quoting myself: [...]`write your own mysql_* layer.`. That means: rewrite the `mysql_*` functions to use `mysqli_*`. – Ismael Miguel Apr 07 '17 at 12:00
  • thank you for your comment but i have shortage of time. so is there any other way? –  Apr 07 '17 at 12:01
  • @Fred-ii- After some thinking, I still can't see how that is a duplicate of this one. The question there is "Why shouldn't I use `mysql_*`?", while this is closer to "Oh no! I have PHP 7.0, which doesn't have `mysql_`, but this huge code was made with it in mind. What can I do now?". Both are very related, but ask distinct things. – Ismael Miguel Apr 07 '17 at 14:13

1 Answers1

0

Here's something you can try: You can re-write the functions using mysqli_*.

This is just a starting point!

<?php
    if(!function_exists('mysql_connect') && function_exists('mysqli_connect'))
    {
        $_GLOBALS["\0MYSQL"] = array();

        function mysql_connect($servername, $username, $password)
        {
            $_GLOBALS["\0MYSQL"][] = mysqli_connect($servername, $username, $password);
        }

        function mysql_select_db($database_name)
        {
            return mysqli_select_db(end($_GLOBALS["\0MYSQL"]), $database_name);
        }

        [...]
    }

This is just a proof-of-concept and is meant to exemplify what I mean.
I'm not sure if someone already wrote this, and my Google-fu is terrible.

Also, don't forget to define all the constants that you use from mysql_*.

Hope this helps.

Ismael Miguel
  • 4,185
  • 1
  • 31
  • 42