Announcement

Collapse
No announcement yet.

BLOB/VarBinary to file

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

  • BLOB/VarBinary to file

    I need to execute this code in SC-7, The only thing i am missing is the $connection global var. to the Database. Is that available when I code in PHP ?

    <?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
    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


    • #3
      i understand your point, but i need to execute this PHP code :

      $image = sqlsrv_get_field( $stmt, 0,
      SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY));
      header("Content-Type: image/jpg");
      fpassthru($image);


      I need to get the data on the VarBinary field then save it to a file that Stream..

      Comment


      • #4
        I understand, but you have all necessary connection in you snippet,why need you sc database conn if you are connecting using external libs?
        /Giuseppe

        Professional Scriptcase Services
        Some Customers opinions

        Comment


        • #5
          Giu, very good point, What i do not mentioned in my thread is that i do not have the user and password, remember all that info is embedded in SC in someWhere code.
          But if i can get user and password from SC, it is what I need.

          In summary :

          a) I need a way to get Server, database, User and Password [Parameters that you setup when you open your App for the first time]

          Or

          b) I need the Connection object in order to pass to my function : sqlsrv_query($conn, $tsql, $params);

          Thanks for all your Help..

          Comment


          • #6
            Create your connection object using database global vars

            Global variables containing database access values used by main connection.

            Variables
            Description
            sc_glo_servidor Server name.
            sc_glo_banco Database name.
            sc_glo_tpbanco Database type (mssql, oracle, mysql, etc).
            sc_glo_usuario Connected user name.
            sc_glo_senha Database password access.
            sc_glo_senha_cript Encrypted password (S/N).
            sc_glo_decimal_db Used decimal separator (point or comma).


            Ex. 1:
            $my_database = [sc_glo_banco];
            /Giuseppe

            Professional Scriptcase Services
            Some Customers opinions

            Comment


            • #7
              Excellent GIU, that is what i need...
              Sorry that i did not reply sooner, But i was on Vacactions..
              I will test and let you know the Results...

              Comment


              • #8
                Good to see other people are studying the generated code as well... Thumbs up for Giu

                Comment

                Working...
                X