需要有关 php 中 mysql 连接的帮助
我的 mysql 连接有问题。
我有一个上传照片的 php 脚本,该脚本执行以下操作:
1) mysql connection
2) check user rights for uploading photo (I use a sql query for this)
3) Image processing
4) sql query for insering photo data in database
I have set a mysql connection timeout to 5 s.如果图像处理时间小于 5 秒(mysql 连接超时),则一切正常,否则执行步骤 4)时出现错误,错误为“Mysql 服务器已消失”。
因此,我检查了图像处理后mysql连接是否仍然存在,如果图像处理时间超过5秒,mysql连接就会终止。
我在图像处理(步骤 3)之后添加了此代码,
if(!mysql_ping($conn)){
$conn = mysql_connect('localhost', 'mysqluser', 'mypass');
$db = mysql_select_db('mydb',$conn);
}
但它不起作用!这是我真正的问题。
var_dump($conn)
give a mysql ressource link butmysql_select_db('mydb',$conn)
return FALSE, andmysql_error()
return "mysql server has gone away"Does anybody can help me?
提前致谢。
I have a problem with mysql connection.
I have a php script which upload photo, this script do that:
1) mysql connection
2) check user rights for uploading photo (I use a sql query for this)
3) Image processing
4) sql query for insering photo data in database
I have set a mysql connection timeout to 5 s.
Everything works great if the image processing time is less than 5s (mysql connection timeout) otherwise I got a error when the step 4) is executed, the error is "Mysql server has gone away".
So, I checked if the mysql connection was still alive after the image processing and the mysql connection died if the image processing time is more then 5s.
I added this code after the image processing (step 3)
if(!mysql_ping($conn)){
$conn = mysql_connect('localhost', 'mysqluser', 'mypass');
$db = mysql_select_db('mydb',$conn);
}
but it doesn't work! this is my real problem.
var_dump($conn)
give a mysql ressource link but
mysql_select_db('mydb',$conn)
return FALSE, and
mysql_error()
return "mysql server has gone away"
Does anybody can help me?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
引用自 http://dev.mysql.com/doc/ refman/5.0/en/gone-away.html:
ETC。
Quote from http://dev.mysql.com/doc/refman/5.0/en/gone-away.html:
etc.
首先尝试增加超时,然后在第 4 步后关闭连接
mysql_close()
为什么要增加超时?因为图像处理肯定需要5秒以上,所以就会出现这个问题!
first try increasing the timeout, then close the connection after step 4
mysql_close()
why increase the timeout? because the image processing definitely takes more than 5 secs, so this problem occurs!