Abs
Abs

Reputation: 57966

Performance: PHP and MS SQL Server: SQLCMD using Exec or Driver

I am currrently making queries to my SQL Server using SQLCMD and I run this from PHPs exec() function. I was hoping to clarify that this isn't as efficient as the driver for SQL Server for PHP: http://www.microsoft.com/sqlserver/2005/en/us/PHP-Driver.aspx. I am not sure if this is the same as https://www.php.net/manual/en/book.mssql.php?

I find that everytime I run an exec command it is quite a slow response and I was hoping to get this confirmed before I move to this new driver and implement it. Is there a performance difference using this Driver rather than using the exec function to launch SQLCMD?

I know this is a bit fluffy, but I really appreciate help on this decision.

Thanks all

Upvotes: 0

Views: 1365

Answers (2)

Pascal MARTIN
Pascal MARTIN

Reputation: 401162

Launching another command, using exec or one of the other Program execution Functions, takes time ; using some PHP function/classes will probably always be faster -- and easier :

  • no need to launch another command
  • no problem for parameters passing
  • no parsing of the output : you'll get native PHP data as output
  • less problems like "command not found", or differences between UNIX/Linux and Windows
  • no problem with safe_mode and the like

I would definitly go with using some function provided by a PHP extension, instead of using exec.


As a sidenote, in this specific case :

  • the SQL Server driver for PHP is currently only available on Windows platforms -- doesn't exist for Linux :-(
  • it's not available as a PDO driver : you have to use the specific sqlsrv_* functions

Upvotes: 1

Zak
Zak

Reputation: 25215

Ugg, yeah, get rid of your exec and use the php client library. You also won't have to deal with parsing your result sets back off the command line.

Upvotes: 2

Related Questions