Good time of the day, colleagues!
I need to get the result of the function on the server ms sql for the site working through php
<?php $serverName = "127.0.0.1\sqlexpress"; /* Get UID and PWD from application-specific files. */ $uid = file_get_contents("C:\Files\uid.txt"); $pwd = file_get_contents("C:\Files\pwd.txt"); $connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd, "Database"=>"FPatology"); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn === false ) { echo "Unable to connect.</br>"; die( print_r( sqlsrv_errors(), true)); } $tsql="select * from dbo.fn_select_PHPServerA()"; --функция на сервере без параметров! if ($res = sqlsrv_query($conn,$tsql)) { } else { echo "Statement could not be prepared.\n"; die( print_r( sqlsrv_errors(), true)); } echo "<table align=center, border=1>\n"; echo "\t<tr>\n \t\t<th> Поле1 </th>\n \t\t<th> Поле2 \t\t</th>\n \t\t<th> Поле3</th>\n \t\t<th> Поле4</th>\n \t\t<th> Поле5 </th>\n \t\t<th> Поле6</th>\n \t\t<th> Поле7 </th>\n \t\t<th> Поле8 </th>\n \t\t<th> Поле9 </th>\n \t\t<th> Поле10 </th>\n \t\t<th> Поле11 </th>\n \t\t<th> Поле12 </th>\n \t\t<th> Поле13</th>\n \t\t<th> Поле14 </th>\n \t\t<th> Поле15 </th>\n \t</tr>\n"; for ($i=0; $row = sqlsrv_fetch($res); $i++) { echo "\t<tr> \n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 0 )."</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 1 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 2 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 3 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 4 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 5 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 6 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 7 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 8 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 9 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 10 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 11 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 12 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 13 )."\t\t</td>\n"; echo "\t\t<td> ".sqlsrv_get_field( $res, 14 )."\t\t</td>\n"; echo "\t</tr>\n"; } echo "</table>\n"; sqlsrv_free_stmt( $res); sqlsrv_close( $conn); ?>
Everything works fine, I get a table with data. but as soon as I try to perform a function on the server with the passed parameters and write
$tsql="select * from dbo.fn_select_PHPServerB(@ndoc)"; --функция на сервере с параметрами!
adding the actual parameters
$ndoc="7"; $params=array($ndoc); if ($res = sqlsrv_query($conn,$tsql,$params))
when opening the site gives me
## Statement could not be prepared. ##
and further crocodiles
question: how do I give the command to execute the function with parameters in advance, thanks