Bootstrap

codeigniter mysql 挂掉,CodeIgniter“ MySQL已经消失”

I know there are many topics about MySQL's "Server has gone away" error, but this one seems to be happening randomly and in a non-favorable condition.

I'm using CodeIgniter 3.0. In the research I did, I found someone else with this problem using this framework but that issue was never solved. He/she stated that it was CodeIgniter's fault because the database had no problems with other applications.

People say this issue is usually because of a timeout, but I don't think there could be a timeout where the amount of data is minimal. In fact, the tables where I'm trying to pick up information from have no more than 5 rows. I'm just doing a SELECT * FROM table WHERE id = x so I don't really think that there's a performance issue with that amount of data.

My code for the query goes as follows:

public function getArticleByRef($ref)

{

$this->db->reconnect();

$article = array();

$mods = array();

$run = array();

$supplier=array();

$query = ($this->db->get_where('PABE_articles',array('Reference' => $ref),1));

$article = $query->result_array();

if(!$article)

return array('article' => null,'mods' => $mods,'run' => $run,'supplier'=>$supplier);

$id = $article[0]['id'];

$query = $this->db->get_where('PABE_mods',array('idarticle'=>$id));

$mods = $query->result_array();

$query = $this->db->select('*')

->from('PABE_run')

->where('idarticle', $id)

->order_by('Color asc,Number asc')

->get();

$run = $query->result_array();

$query = $this->db->get_where('PABE_supplieres',array('Reference' => $article[0]['Referencesupplier']));

$supplier= $query->result_array();

return array('article' => $article,'mods' => $mods,'run' => $run,'supplier'=>$supplier);

}

As you can see, I do four queries. Then again, in none of these tables there's more than 5 rows.

The number of columns for the tables are:

Articles: 27

Supplier: 2

Run: 3

Mods: 4

The problem is totally random, so I can't complete this application without fixing it. Something that's pretty weird is that, even though this problem gets reported, all data from the database gets loaded with no problems.

Everything's running on my PC - Localhost.

解决方案

Could be that your mysql is not configured to support persistent connections. Try commenting the reconnect line or edit my.ini and enable persistent connections.

regards

;