Wednesday, 15 February 2012

exec - Using PHP and calling sqlcmd -



exec - Using PHP and calling sqlcmd -

i've been wracking brain on in trying phone call sqlcmd in php (iis/windows) i'm @ finish loss 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 nil gets generated in

c:\temp

folder. tried running manually start / run , runs without issues. tried exec($sql), using total absolute path sqlcmd, tried calling cmd.exe , sqlcmd far nothing.

i added iusr total , users total permission folder create sure it's not permissions iis still nothing.

i used proc mon see if tell me , i'm not seeing related sqlcmd, cmd, or php.exe (that lead me reason why - entries show standard phone call entries).

i've done extensive amount of searching php , calling sqlcmd seems people phone call batch file sqlcmd in it. can't here guidance appreciated!

here's possible idea, utilize batch script have work done this:

sqlcmd.bat

@echo off cd /d "c:\program files\microsoft sql server\100\tools\bin\" sqlcmd -s %1 -d %2 -u %3 -p %4 -q "exec generateinstallscript 123456890" -o c:\temp\sqlscripts.sql

then phone call batch script using php this:

test.php

<?php $servername = 'xyz'; $databasename = 'xyz'; $username = 'xyz'; $userpassword = 'xyz'; shell_exec("sqlcmd.bat $servername $databasename $username $userpassword"); echo 'done'; ?>

php exec shell-exec sqlcmd

No comments:

Post a Comment