I've been wracking my brain over this in trying to call sqlcmd in PHP (IIS/Windows) but I'm at a complete loss as to why it's not working.
Code:
$sql = 'sqlcmd -S '.$serverName.' -d '.$databasename.' -U '.$userName.' -P '.$userPassword.' -q "exec GenerateInstallScript 123456890" -o C:\temp\sqlscripts.sql';
shell_exec($sql);
The code runs but nothing gets generated in the
C:\temp
folder. I tried running it manually from start / run and it runs without any issues. I even tried just exec($sql)
, using full absolute path to sqlcmd, tried calling cmd.exe and then sqlcmd but so far nothing.
I added IUSR full and Users full permission to the folder as well just to make sure it's not permissions from IIS but still nothing.
I also used proc mon to see if that would tell me anything and I'm not seeing anything related to sqlcmd, cmd, or php.exe (that would lead me to a reason why - entries show up but just standard call entries).
I've done an extensive amount of searching about PHP and calling SQLCMD but it seems like most people call a batch file with the sqlcmd in it. I can't really do that here so any guidance will be appreciated!
sqlcmd
in theshell_exec
function?