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

Asked

Viewed 372 times

0

Times on the system where work happens to appear the following errors mysql_error() = "" and mysql_errno() = "0", but it 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 for it and what I found in the documentation of Mysql when the mysql_errno() returns 0 means that the query was successfully executed, but if it was successfully executed because it entered the else of my parole ?

  • In php zero is converted to false, then it falls on Else. pq does not change the structure a bit. Its Procedure returns value?

  • @rray but ai in the case was successfully executed, both that running on Workbench works, and the return 0 of the function msql_errno() it means that everything went right, and yes the Procedure returns the data with which I fill the page and the strange thing is that now it is working perfectly without having been made any changes, I saw people in the English stackoverflow who had similar problems where mysql_error() = “” and mysql_errno() = “0” but their solutions did not suit me

1 answer

1

If you have multiple open connections it will cause the failure, because instead of them they get the connection error in Handle $this->conn you’ll get the last open connection, so you can try this:

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

Functions with prefix MYSQL_ were removed in PHP7, update urgently

it is necessary to note that the functions mysql_ no longer receive updates, such as fixes and improvements and are considered obsolete almost 10 years ago and this is the vital point for you not to use more mysql_, because in the future it will soon cease to exist for the new versions of PHP as I mentioned in /a/66489/3635

You can choose PDO or Mysqli (your choice):

Read more on: Mysqli vs PDO - which is the most recommended to use?

  • OK ,I will implement this in the system but as I said it is a very atypical situation will be difficult to test. Obs:is being created an updated version of the system, but as the old one is still in production it is with the methods mysql_, but thank you

  • not , just once

  • @Viniciusshiguemori may be some fault or confusion and accidentally mysql_connect is running twice, being in the same script or even another script included that has nothing to do with this.

  • I searched here in the code, I did not find it running 2x and if that was the case my problem would not always happen ?

  • @Viniciusshiguemori Not because it would depend on the type of error, then imagine that maybe $query = mysql_query($sql, $this->conn) fails, due to a wrong query that was generated by a "GET" or "POST" but there was already another connection elsewhere (which came later), at the time the query fails the mysql_error will search the Handler of the last connection and so returned empty. In short, the error can be anything, it can be some invalid data that is being added in the query or even some limitation imposed on the database server, can not state

  • @Viniciusshiguemori I will await the test with the change you suggest, let me know if anything changes or not.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.