tags:

views:

559

answers:

4

Below is the code that i cannot get to work. I know i have established a connection to the database but this returns nothing. What am i doing wrong?

$result = "SELECT * FROM images WHERE path = ?";
$params = array("blah");
$row = sqlsrv_query($conn, $result, $params);

$finished = sqlsrv_fetch_array($row);


if($finished)
{
echo "blach";
}
+1  A: 

You may need to replace your ntwdblib.dll as explanied on the mssql_connect() page of the php.net manual.

A: 

Would it be worth checking that the query is not returning an error?

$result = "SELECT * FROM images WHERE path = ?";
$params = array("blah");
$row = sqlsrv_query($conn, $result, $params);

if( $row === false ) {
    print_r(sqlsrv_errors());
}
Tom Haigh
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -14 [code] => -14 [2] => An invalid parameter was passed to sqlsrv_query. [message] => An invalid parameter was passed to sqlsrv_query. ) )This is the error it produces. Cheers
odd.. what's the column type form images.path ?
Tom Haigh
what happens if you do$params = array(array('blah', SQLSRV_PARAM_IN,SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR),SQLSRV_SQLTYPE_VARCHAR('max')));
Tom Haigh
same error as before.
A: 

What if you don't use a literal? Most of the MSDN examples use variables.

I'd try:

$result = "SELECT * FROM images WHERE path = ?";
$var = "blah";
$row = sqlsrv_query($conn, $result, array($var));

$finished = sqlsrv_fetch_array($row);
matt.mercieca
A: 

I m facing same problem and even i m using literal also, see my code:

function GetAuto()
{
$params = array(array("InquiryForm"),   
    array("Last"),
    array(0),
    array(""),
    array($LastAuto,SQLSRV_PARAM_OUT,SQLSRV_SQLTYPE_DECIMAL(20, 0)));
$processauto = "{CALL GetSpecificAuto(?,?,?,?,?)}";  
$getauto = sqlsrv_query($conn,$processauto,$params);
if($getauto === false)
{
 echo "Error in executing GetSpecificAuto for LastRecord. \n";
 die( print_r( sqlsrv_errors(), true));
}
sqlsrv_free_stmt( $getauto);

return $LastAuto;

}

$auto = GetAuto();
echo $auto;

its not working. My Connection is also working fine. I have checked it with sqlsrv_server_info(), i m also trying this same with the return type array, i need to create a function which returns a array, but that function is also not working.

any help pls.....

Shwetal
If you have a follow up question you should better post it asa new question, not as an answer to this old question.More people will read it since old questions are not frequented very much.
sth