Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6725565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:49:24+00:00 2026-05-26T09:49:24+00:00

I have to port a LAMP-based project that uses PHP-MSSQL to connect to a

  • 0

I have to port a LAMP-based project that uses PHP-MSSQL to connect to a SQL Server db. It has to be ported to a WAMP-based machine that uses PHP-SQLSRV to connect to a SQL Server db.

I can get/set data by executing stored procedures. It seems like most types of input variables are pretty simple to get working. But I cannot get input params of type bit to work.

I have tried using various values in PHP that are ‘truthy’ or ‘falsey’, but non of them get me past the error:

  • ‘truthy’ things that didn’t work:

    • 1
    • "1"
    • true
    • "True"
  • ‘falsey’ things that didn’t work:

    • 0
    • "0"
    • false
    • "False"

I have tried using various ways to add an item to the $params array, including omitting optional arguments as well as defining the PHP and SQL data types. Nothing works.

My error message from SQL Server (converted to a JSON object) is:

[{
  "0":"42000",
  "SQLSTATE":"42000",
  "1":8114,
  "code":8114,
  "2":"[Microsoft][SQL Server Native Client 10.0][SQL Server]Error converting data type varchar to bit.",
  "message":"[Microsoft][SQL Server Native Client 10.0][SQL Server]Error converting data type varchar to bit."
}]

To generate this error message, I passed a value of 0 or 1, neither of which is a varchar or even a string.

To maintain maximum compatibility I do not want to alter the Stored Procedure to Cast/Convert data on SQL Server. I want this to work from PHP keeping Stored Procedure unchanged.


PHP code:

<?php
  $link = sqlsrv_connect($host,Array("Database"=>$database,"UID"=>$username,"PWD"=>$password));
  $sql = " { call StoredProcedureName ( @input_param_of_bit_type=? ) } ";
  $param1 = 1;
  $params = Array(
    Array(&$param1, SQLSRV_PARAM_IN)
  );
  $stmt = sqlsrv_prepare($link,$sql,$params);
  if ($stmt===false) {
    // handle error
    print_r(sqlsrv_errors,true);
  } else {
    if (sqlsrv_execute($stmt)===false) {
      // handle error.  This is where the error happens
      print_r(sqlsrv_errors,true);
    } else {
      // success! It never gets here, though.
    }
  }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:49:24+00:00Added an answer on May 26, 2026 at 9:49 am

    Re-ordering the order of the named parameters made this work. I had to use SQL Server Management Studio software and Profile Tracing to see what was different about executing the Stored Procedure from php-sqlsrv vs. executing it directly from within SQL Server Management Studio.

    After I put the input parameters in the exact order used by SQL Server Management Studio, everything worked OK.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a port monitor dll, that I instaling by call AddMonitor function of
Advice required on architecting module I have a PORT Listener that listens to a
I have a script that links to the server I am hosting (IP can
I have to port an existing project to Maven, and it includes a resource
I am using jboss 4.2 server and oracle xe both have same port ie
I work on a project written for MSVCC / Windows, that I have to
i read in some stackOverflow post that The host would need to have port
I can not connect to my EC2 instane. I have opened port 21 in
I have a port that is bind()'d to INADDR_ANY. I am receiving datagrams successfully.
I have my dev environment set up as a Ubuntu Server (with LAMP installation)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.