Solved

Could the php mssql_query function be locking tables in the SQL database?

Posted on 2013-11-14
3
401 Views
Last Modified: 2013-11-14
Hi,  I am using the following code to query a remote SQL server with a select statement.  Could this be locking that database?

Thanks for any direction you can give!

$link = @mssql_connect($myServer,$myUser,$myPass);
mssql_select_db($myDB) or die('Couldn\'t load database');
$qry = "Select cast(GUIDProduct as varchar(36)) as myProductGUID, DATALENGTH(ProductPicture) as myImageSize, *
		from Product";
$rs = mssql_query($qry);
$RowCount = mssql_num_rows($rs);
if($RowCount>0){
	while($rows = mssql_fetch_assoc($rs)){
		//do something with recordset
	}
}

Open in new window

0
Comment
Question by:lthames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39650024
It could, yes.

Typically when a query is executed in mssql that query places a shared lock on the table(s) so other operations requiring an exclusive lock on the table(s) involved would need to wait until the shared lock is released.
If READ_COMMITTED_SNAPSHOT is set to OFF (the default), the Database Engine uses shared locks to prevent other transactions from modifying rows while the current transaction is running a read operation.
http://technet.microsoft.com/en-us/library/ms173763(v=sql.105).aspx

This behaviour can be modified e.g:

turning on the database READ_COMMITTED_SNAPSHOT option
including "with nolock" into the query sql

Note these are NOT the same thing, using "with nolock" can return as yet uncommitted records that subsequently might be rolled back.
0
 

Author Comment

by:lthames
ID: 39650097
Thank you for your quick response.  

This definitely explains what's going on.  They are trying to import products into the database (which in that app requires exclusive lock during the import)  and at the same time my php script is syncing the products to their webstore . . . . . and their internet connection is so slow that a query that normally takes 1-2 seconds is taking 3 minutes!!!!!!!!!!
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39650132
& Thanks for the quick grading :)

You will need to discuss this with the client then. If "syncing" I'd assume you only want valid data on the website, so using "with nolock" might be risky given that:
> an import might fail
> you are also being slowed down by connection speed.

They may be willing to use READ_COMMITTED_SNAPSHOT on perhaps?

Good luck with this project.

Paul
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question