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

  • Home
  • SEARCH
  • 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 7851833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:16:30+00:00 2026-06-02T19:16:30+00:00

I’m trying to use PHP with Microsoft SQL Server 2008 R2 and it makes

  • 0

I’m trying to use PHP with Microsoft SQL Server 2008 R2 and it makes me want to die. I have a stored procedure that works perfectly via FreeTDS that I run in the terminal on my Mac, works perfectly in Visual Studio, and works perfectly via ASP.NET on a FrontPage server. It fails miserably through PHP 5.3.2 on an Ubuntu web server, however. In the procedure, I set up a few temp tables and insert into them from a giant table, which invariably contains some nulls here and there. The error I get is

Cannot insert the value NULL into column 'Notes', table 'tempdb.dbo.#termtable1__00000000BE0B'; column does not allow nulls. INSERT fails.

only with a billion more underscores. Someone posted this as a bug here, but it hasn’t got much attention. My best attempt was specifying a NULL constraint on every column of every temp table, but it didn’t help. Also tried SET ANSI_NULLS ON. I don’t have much access to any of these servers as far as patches and drivers go, nor do I have a heck of a lot of access to the people who do. I don’t think they’re going to want to do much to help me out, but if someone has a really good idea, I’ll try to get it done. Oh, and, it should be noted that the same procedure in SquirrelSQL (via Microsoft JDBC driver) gives bizarre, half-correct results. Thanks.


EDIT:

I fixed the link, actually just copied and pasted the wrong URL altogether. Here’s the T-SQL where the temp table gets declared. I tried putting NULL after each datatype. There are five of them just like this.

    CREATE TABLE #termtable1
        (SerialNumber varchar(50), SR varchar(50), LeaseTag varchar(50), Component varchar(50), 
        Fund int, Org int, Program varchar(50), FirstName varchar(80), LastName varchar(30), 
        Department varchar(50), Location varchar(50), UserID nvarchar(20), Notes nvarchar(MAX), 
        Manufacturer varchar(50), Model varchar(50), Maintenance bit, OrderNumber varchar(50), 
        ContractNumber varchar(50), ParentTag varchar(50));

They get inserted into via dynamic SQL, which is why I can’t use a table variable instead (scope issues):

DECLARE @sqlstring nvarchar(MAX);
DECLARE @params nvarchar(200) = N'@term1 varchar(100), @term2 varchar(100), @term3 varchar(100), @term4 varchar(100), @term5 varchar(100)';
DECLARE qryCursor CURSOR FOR SELECT * FROM @terms;
OPEN qryCursor;
FETCH NEXT FROM qryCursor INTO @term1, @term2, @term3, @term4, @term5;
DECLARE @termrow int = 1;
WHILE (@@FETCH_STATUS = 0)
BEGIN
    SET @sqlstring = N'INSERT INTO #termtable' + CAST(@termrow AS varchar) + N' SELECT * FROM dbo.NewUserInfo WHERE ';
    DECLARE @i int = 1;
    WHILE (@i <= 5)
    BEGIN
        SET @sqlstring = @sqlstring +
        N'(SerialNumber LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'SR LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'LeaseTag LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Component LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Fund LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Org LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Program LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'FirstName LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'LastName LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Department LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Location LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Notes LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Manufacturer LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Model LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'Maintenance LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'OrderNumber LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'ContractNumber LIKE @term' + CAST(@i AS varchar) + N' OR ' +
         N'ParentTag LIKE @term' + CAST(@i AS varchar) + N') OR ';
        SET @i = @i + 1;
    END
    SET @sqlstring = @sqlstring + N'(0 = 1)';
    EXECUTE sp_executesql @sqlstring, @params, @term1=@term1, @term2=@term2, @term3=@term3, @term4=@term4, @term5=@term5;
    SET @termrow = @termrow + 1;
    FETCH NEXT FROM qryCursor INTO @term1, @term2, @term3, @term4, @term5;
END

The PHP is simple. $result = mssql_query("EXEC QuickSearch '" . $search . "';"); It only gives the error when it finds a NULL in the NewUserInfo table. Frequently in “Notes.”

  • 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-06-02T19:16:31+00:00Added an answer on June 2, 2026 at 7:16 pm

    Ok guys, I’m sorry. Putting NULL after every datatype did work. I must have missed a couple when I tried it the first time. The table declaration should be like this:

    CREATE TABLE #termtable1
            (SerialNumber varchar(50) NULL, SR varchar(50) NULL, LeaseTag varchar(50) NULL, Component varchar(50) NULL, 
            Fund int NULL, Org int NULL, Program varchar(50) NULL, FirstName varchar(80) NULL, LastName varchar(30) NULL, 
            Department varchar(50) NULL, Location varchar(50) NULL, UserID varchar(20) NULL, Notes varchar(MAX) NULL, 
            Manufacturer varchar(50) NULL, Model varchar(50) NULL, Maintenance bit NULL, OrderNumber varchar(50) NULL, 
            ContractNumber varchar(50) NULL, ParentTag varchar(50) NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put

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.