从php4和5迁移到php7的MySQL在某些功能上被卡住

时间:2018-12-13 01:42:18

标签: mysqli php-7

对不起,我只是php的新手,我的网站已有10年历史,并且被php4和5.2困扰。 在cenos 5上,主机提供商要求我更新所有系统,因为存在太多风险,现在有些黑客在我的服务器上安装了一个隐藏的矿工cryto货币,我们花了一个月时间仍无法查明,每天只能阻止ip /端口,而那些会回来的。

现在系统将是php7和mysql 5.7 当我使用waamp服务器进行本地测试时出现很多错误。

我很难用mysqli_query将旧的php4类转换为mysql的php7。和第一个功能sql_query我不能使其工作。 绒毛是样品,请帮助:

    $dbhost = "localhost";
$dbuname = "root";
$dbpass = "pass";
$dbname = "ddd";
$prefix = "vvv";
$user_prefix = "uuu";
$dbtype = "MySQLi";

$db = new sql_db($dbhost, $dbuname, $dbpass, $dbname, false);

//test1:
  $result = $db->sql_query("SELECT active, view FROM ".$prefix."_modules limit 1");
  list($mod_active, $view) = $db->sql_fetchrow($result);
 echo $mod_active;
 echo '\n=========================\n';
 // test2
 $sql = "SELECT sid,title FROM ".$prefix."_stories ORDER BY sid DESC LIMIT 10"; $content =''; $result = $db->sql_query($sql);
 while($row = $db->sql_fetchrow($result)) {
     echo $content .= $row['sid'].' : '.$row['title'];
 }  


class sql_db
{

    var $db_connect_id;
    var $query_result;
    var $row = array();
    var $rowset = array();
    var $num_queries = 0;

    //
    // Constructor
    //
    function __construct($sqlserver, $sqluser, $sqlpassword, $database, $persistency = false)
    {

        $this->persistency = $persistency;
        $this->user = $sqluser;
        $this->password = $sqlpassword;
        $this->server = $sqlserver;
        $this->dbname = $database;

        if($this->persistency)
        {
            $this->db_connect_id = mysqli_connect("p:".($this->server), $this->user, $this->password);
        }
        else
        {
            $this->db_connect_id = mysqli_connect($this->server, $this->user, $this->password);
        }
        if($this->db_connect_id)
        {
            if($database != "")
            {
                $this->dbname = $database;
                $dbselect = mysqli_select_db($this->db_connect_id, $this->dbname);
                if(!$dbselect)
                {
                    mysqli_close($this->db_connect_id);
                    $this->db_connect_id = $dbselect;
                }
            }
            return $this->db_connect_id;
        }
        else
        {
            return false;
        }
    }

    //
    // Other base methods
    //
    function sql_close()
    {
        if($this->db_connect_id)
        {
            if($this->query_result)
            {
                mysqli_free_result($this->query_result);
            }
            $result = mysqli_close($this->db_connect_id);
            return $result;
        }
        else
        {
            return false;
        }
    }

    //
    // Base query method
    //
    function sql_query($query = "", $transaction = FALSE)
    { 
        // Remove any pre-existing queries
        unset($this->query_result);
        if($query != "")
        {
            $this->query_result = mysqli_query($this->db_connect_id, $query);
        }
        if($this->query_result)
        {
            //print_r($this->query_result);
            unset($this->row[$this->query_result]);
            unset($this->rowset[$this->query_result]);
            return $this->query_result;
        }
        else
        {
            return ( $transaction == END_TRANSACTION ) ? true : false;
        }
    }

    //
    // Other query methods
    //
    function sql_numrows($query_id = 0)
    {
        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $result = mysqli_num_rows($query_id);
            return $result;
        }
        else
        {
            return false;
        }
    }
    function sql_fetchrow($query_id = 0)
    {       

        if(!$query_id)
        {
            $query_id = $this->query_result;
        }
        if($query_id)
        {
            $this->row[$query_id] = mysqli_fetch_array($query_id);
            return $this->row[$query_id];
        }
        else
        {
            return false;
        }
    }
}

2 个答案:

答案 0 :(得分:0)

我想知道您是否查看过迁移文档:http://php.net/manual/en/migration70.php

您的网站将抱怨某些功能,因此,如果将这些功能与迁移文档交叉引用,您将能够解决很多问题。

答案 1 :(得分:0)

mysql和mysqli之间几乎没有区别。由于您有自己的单独的mysql类,因此建议您在该类中进行一些修改。最近,我写了一个关于这个的博客。你可以看看您也可以找到示例代码。

LINK