title: Using PHP and calling sqlcmd
body: <p>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.</p>
  
  <p>Code:</p>
  
  <pre><code> $sql = 'sqlcmd -S '.$serverName.' -d '.$databasename.' -U '.$userName.' -P '.$userPassword.' -q "exec GenerateInstallScript 123456890" -o C:\temp\sqlscripts.sql';
      shell_exec($sql);
  </code></pre>
  
  <p>The code runs but nothing gets generated in the </p>
  
  <blockquote>
    <p>C:\temp</p>
  </blockquote>
  
  <p>folder.  I tried running it manually from start / run and it runs without any issues.  I even tried just <code>exec($sql)</code>, using full absolute path to sqlcmd, tried calling cmd.exe and then sqlcmd but so far nothing.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>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!</p>