简体   繁体   English

PDO数据库连接问题

[英]PDO Database Connections Problem

Over a year ago I created my own database classes which use PDO, and handle all preparing, executing, and closing connections. 一年多以前,我创建了自己的使用PDO的数据库类,并处理所有准备,执行和关闭连接。 These classes have been working great up until now. 到目前为止,这些课程一直在努力。

There are two different database severs I am grabbing from, MySQL, and MS SQL Express. 我要从中获取两种不同的数据库服务器:MySQL和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. 我正在从MySQL服务器检索员工ID,并使用它从MS SQL服务器获取该员工信息。 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. 大约有11k条记录来自MySQL服务器,我的程序在崩溃之前出现了如下错误,直到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

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. 该程序似乎无法连接到数据源,但是在此之前,它正在运行完全相同的查询大约30次并且没有问题。 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 克雷格·梅特利斯(Craig Metrolis)

UPDATED 更新

Ok, I found the problem, I was using closeCursor after preparing the query, and before the execute. 好的,我发现了问题,在准备查询之后和执行之前,我正在使用closeCursor。 I took out the closeCursor and it seems to have fixed this problem.... BUT WHY?? 我拿出closeCursor,似乎已经解决了这个问题。...为什么? That does not make any sense to me..... 对我来说这没有任何意义.....

PDOStatement::closeCursor() frees up the connection to the server so that other SQL statements may be issued, but leaves the statement in a state that enables it to be executed again. PDOStatement :: closeCursor()释放与服务器的连接,以便可以发出其他SQL语句,但将语句保持在使其可以再次执行的状态。

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. 但是,这仍然不能解释为什么它在出现问题之前已经通过了1200条记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM