Announcement

Collapse
No announcement yet.

Global Connection Variable in order to execute sqlsrv_query($conn, $tsql, $params);

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Global Connection Variable in order to execute sqlsrv_query($conn, $tsql, $params);

    I need to execute the following code, But i need the $conn onbject variable that ScriptCase uses in their code,
    What is that variable?
    Is it possible to use it ?

    Thanks in advance...

    <?php
    /* Connect to the local server using Windows Authentication and
    specify the AdventureWorks database as the database in use. */
    $serverName = "(local)";
    $connectionInfo = array( "Database"=>"AdventureWorks");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
    if( $conn === false )
    {
    echo "Could not connect.\n";
    die( print_r( sqlsrv_errors(), true));
    }

    /* Set up the Transact-SQL query. */
    $tsql = "SELECT LargePhoto
    FROM Production.ProductPhoto
    WHERE ProductPhotoID = ?";

    /* Set the parameter values and put them in an array. */
    $productPhotoID = 70;
    $params = array( $productPhotoID);

    /* Execute the query. */
    $stmt = sqlsrv_query($conn, $tsql, $params);
    if( $stmt === false )
    {
    echo "Error in statement execution.</br>";
    die( print_r( sqlsrv_errors(), true));
    }

    /* Retrieve and display the data.
    The return data is retrieved as a binary stream. */
    if ( sqlsrv_fetch( $stmt ) )
    {
    $image = sqlsrv_get_field( $stmt, 0,
    SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
    header("Content-Type: image/jpg");
    fpassthru($image);
    }
    else
    {
    echo "Error in retrieving data.</br>";
    die(print_r( sqlsrv_errors(), true));
    }

    /* Free statement and connection resources. */
    sqlsrv_free_stmt( $stmt);
    sqlsrv_close( $conn);
    ?>

  • #2
    Please, don't duplicate post.

    Mentioned in other thread:
    Sorry, but don't understand your question. What's your problem exactly? What $connection global are you talking about?

    Why don't use sc_lookup() and sc_select() macros to connect to your database?

    Regards.
    /Giuseppe

    Professional Scriptcase Services
    Some Customers opinions

    Comment

    Working...
    X