Error mysql_error ()="" and mysql_errno ()="0"

0

Sometimes in the system where work happens the following errors appear mysql_error() = "" and mysql_errno() = "0" , but this happens very rarely.

My code:

// Essa função está dentro de uma class do meu sistema 
// Exemplo : $sql = "Call procedure(1)" obs:no meu sistema trabalhamos com procedures

public function executa($sql){

    if($query = mysql_query($sql, $this->conn)){

       return $query;

    }else {

       echo mysql_error(); 
       echo "<hr>"; 
       echo mysql_errno(); 
       echo "<hr>"; 
       echo $sql; 
       die();

    }

}

I searched about it and from what I found in MySql documentation when the mysql_errno() returns 0 means that the query was executed successfully, but if it was successfully executed because it entered the else of my conditional?

    
asked by anonymous 21.11.2017 / 21:09

1 answer

1

If you have multiple open connections this will cause the failure, because instead of picking up the connection error on the handle in $this->conn will get the last connection open, then you can try this:

   echo mysql_error($this->conn); 
   echo "<hr>"; 
   echo mysql_errno($this->conn); 

Prefixed functions MYSQL_ have been removed in PHP7, update urgently

It should be noted that mysql_ functions do not receive more updates like fixes and improvements and are considered obsolete for almost 10 years and this is the vital point for you not to use mysql_ anymore, because in the near future it will no longer exist for the new PHP versions as I mentioned in link

You can choose PDO or Mysqli (your choice):

Read more at: MySQL vs PDO - Which is the most recommended to use?

    
21.11.2017 / 21:19