views:

56

answers:

1

Hey Everyone,

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.....

A: 

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.

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.

R. Bemrose
Thanks for the response R. Yeah it is very strange also that I have been using these queries almost exactly like these ones in all of my other programs with no problems. I also figured that if I am creating new objects each time that the closeCursor should only close the sth in the current object. Do you think I should just leave it out? Or is it better if I find a way to work it in?
Metropolis
@Metropolis: Sorry about not replying sooner. The cursor should automatically be closed when the PDOStatement goes out of memory, so you should be OK leaving it off.
R. Bemrose
Cool thanks for the reply R :)
Metropolis