0

Anyone who has any idea how to resolve this issue.

While creating pdf if it takes more then few minutes then mysql connection is not working. To overcome this issue I have recreated the mysql connection but it is giving below error.

Code

<?php

    
    $query = "INSERT INTO plotch_vendor_invoice(" . implode(', ', array_keys($fields_arr)) . ") VALUES ('" . implode("', '", $fields_arr) . "')";
    echo "\n $query \n";
    $resultSet = mysql_query($query, $this->dbConn);
    if(!$resultSet){
        echo '\n Mysql Reconnect \n';
        $this->dbConn = mysql_connect(HOST_NAME, USER_NAME, PASSWORD) or die("Couldn't connect.");
        mysql_select_db(DB_NAME, $this->dbConn) or die("Unable to select database"); //Mysql Reconnect \nUnable to select database
        mysql_query($query, $this->dbConn);
    }
?>

ERROR: PHP Warning: mysql_query(): MySQL server has gone away in PHP Warning: mysql_query(): Error reading result set's header in Mysql Reconnect \nUnable to select database

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • 1
    Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Nov 02 '20 at 17:20
  • Are you really still using PHP 5? If you are still using PHP 5 I strongly recommend to upgrade as soon as possible. This version is no longer supported. [Let Rasmus Lerdorf explain it to you](https://youtu.be/wCZ5TJCBWMg?t=2434) – Dharman Nov 02 '20 at 17:23

0 Answers0