PDO数据库连接问题
一年多前,我创建了自己的数据库类,它使用 PDO,并处理所有准备、执行和关闭连接。到目前为止,这些课程一直运行良好。
我从两个不同的数据库服务器获取:MySQL 和 MS SQL Express。我正在从 MySQL 服务器检索员工 ID,并使用它从 MS SQL 服务器获取该员工信息。 MySQL 服务器大约有 11k 条记录,而我的程序仅通过 1200 条就崩溃并出现如下错误。
Connection failed (odbc:Driver=FreeTDS;Servername=MSSQLExpress;Database=SMDINC) Class (PDOException)
SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source
该程序似乎无法连接到数据源,但在此之前它运行了大约 30 次完全相同的查询并且没有任何问题。另外,我已经彻底检查了查询中的所有数据,一切看起来都很好。
我相信问题可能是创建了太多连接,但我尝试关闭许多不同地方的所有连接,但似乎没有任何方法可以解决问题。任何调试帮助或建议将不胜感激!
Craig Metrolis
更新
好的,我发现了问题,我在准备查询之后、执行之前使用了 closeCursor。我拿出 closeCursor ,它似乎已经解决了这个问题......但是为什么?这对我来说没有任何意义......
Over a year ago I created my own database classes which use PDO, and handle all preparing, executing, and closing connections. These classes have been working great up until now.
There are two different database severs I am grabbing from, MySQL, and MS SQL Express. I am retrieving an employee id from the MySQL server and using it to get that employees information from the MS SQL server. There are about 11k records coming from the MySQL server and my program is only making it through 1200 before crashing with an error like the following.
Connection failed (odbc:Driver=FreeTDS;Servername=MSSQLExpress;Database=SMDINC) Class (PDOException)
SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source
It seems like the program is not able to connect to the data source, but it is running the exact same query about 30 times before this and having no problem. Also, I have thoroughly checked all of the data coming into the query and it all looks fine.
I believe the issue may be that there are to many connections being created, but I have tried to close all connections in many different places, and nothing seems to be fixing the problem. Any debugging help, or suggestions would be appreciated!
Craig Metrolis
UPDATED
Ok, I found the problem, I was using closeCursor after preparing the query, and before the execute. I took out the closeCursor and it seems to have fixed this problem.... BUT WHY?? That does not make any sense to me.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
换句话说,它正在关闭你与你的联系。
但这仍然无法解释为什么在问题发生之前它已经完成了 1200 条记录。
In other words, it was closing your connection on you.
That still doesn't explain why it got through 1200 records before the problem occurred, though.