Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locking a SQL Server Database with PHP

I'm wanting extra security for a particular point in my web app. So I want to lock the database (SQL Server 2005). Any suggestions or is this even necessary with SQL Server?

Edit on question:

The query is failing silently with no errors messages logged, and does not occur inside of a transaction.

Final Solution:

I never was able to solve the problem, however what I wound up doing was switching to MySQL and using a transactional level query here. This was not the main or even a primary reason to switch. I had been having problems with SQL Server and it allowed me to have our CMS and various other tools all running on the same database. Previous we had a SQL Server and a MySQL database running to run our site. The port was a bit on the time consuming however in the long run I feel it will work much better for the site and the business.

like image 491
Justin Yost Avatar asked Aug 07 '08 17:08

Justin Yost


People also ask

How do I lock a SQL Server database?

Locks are held on SQL Server resources, such as rows read or modified during a transaction, to prevent concurrent use of resources by different transactions. For example, if an exclusive (X) lock is held on a row within a table by a transaction, no other transaction can modify that row until the lock is released.

Can PHP work with SQL Server?

The Microsoft Drivers for PHP for SQL Server enable integration with SQL Server for PHP applications. The drivers are PHP extensions that allow the reading and writing of SQL Server data from within PHP scripts.

What is Pdo_dblib?

PDO_DBLIB is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to Microsoft SQL Server and Sybase databases through the FreeTDS library. This extension is not available anymore on Windows.

Can I use PHP to pull SQL data out?

Data can be fetched from MySQL tables by executing SQL SELECT statement through PHP function mysql_query. You have several options to fetch data from MySQL. The most frequently used option is to use function mysql_fetch_array().


2 Answers

I suppose you have three options.

  1. Set user permissions so that user x can only read from the database.

  2. Set the database into single user mode so only one connection can access it

    sp_dboption 'myDataBaseName', single, true

  3. Set the database to readonly

    sp_dboption 'myDataBaseName', read only, true

like image 196
GateKiller Avatar answered Sep 28 '22 18:09

GateKiller


I never was able to solve the problem, however what I wound up doing was switching to MySQL and using a transactional level query here. This was not the main or even a primary reason to switch. I had been having problems with MSSQL and it allowed me to have our CMS and various other tools all running on the same database. Previous we had a MSSQL and a MySQL database running to run our site. The port was a bit on the time consuming however in the long run I feel it will work much better for the site and the business.

like image 44
Justin Yost Avatar answered Sep 28 '22 18:09

Justin Yost