Answered An invalid parameter was passed to sqlsrv_query

  • Monday, August 13, 2012 9:30 AM
     
      Has Code

    Hi all,

    I have installed php 5.3.13 on a Web Role (windows Azure) and it uses sql azure as database. Following is my code:

    dbConnectDB.php
    ---------------------------

    $uid = myid@myserver;
    $pwd
    = "mypassword";
    $dbname = "mydbname";
    $serverName = "tcp:myserver.database.windows.net,1433";

    $connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database" => $dbname);
    $conn = sqlsrv_connect($serverName, $connectionInfo);
    if($conn == false){
         FatalError("Failed to connect...");
    }

    it seems that $conn is not false.

    index.php
    ---------------------------
    include_once 'dbConnectDB.php';
    include_once 'session.php';
    $login_query = "SELECT * FROM admins WHERE username = ? and password = ?"; 
     $params = array("theUsername", "thepassword");
     $login_result = sqlsrv_query($conn, $login_query,  $params);

     if ($login_result == false){
      die( print_r( sqlsrv_errors(), true));
     }
     
     $login_object = sqlsrv_fetch_object( $login_result);

    Here everything works fine and I can fetch the resultset.
    but If I execute same query in session.php it generates:
    "An invalid parameter was passed to sqlsrv_query"
    as you see on the top of index.php I have inclueded both dbConnectDB.php and session.php so it should work
    in session.php as well.
    Thanks for your advice.

All Replies

  • Monday, August 13, 2012 4:23 PM
     
     Answered Has Code

    I'm guessing you have already included dbConnectDB.php in a different context, try this:

    include 'dbConnectDB.php'; // not include_once


    Rob

  • Wednesday, August 15, 2012 6:32 PM
     
     

    Hi Medes2,

    Did Robert's solution help you out?

    Thanks

    Jonathan


    This posting is provided 'AS IS' with no warranties, and confers no rights.

  • Thursday, September 06, 2012 7:26 AM
     
     

    Hi yes it helped me to find the solution. it seems that I need to get connection parameter again. it was lost.