What is wrong with this insert statement?

I've got a successful connection, my #gant_rows table appears to be in place, but when I run this query:

$karsyn = $mssql_pdo->prepare("INSERT INTO #gant_rows
                        (tool_id)
                         VALUES
                         (:tool_id)
                         ");
                        $karsyn->bindValue(':tool_id', $michelle_row['int_DEVELOPERS_Tool_Id'], PDO::PARAM_INT);
                        $karsyn->execute();
                        $karsyn->debugDumpParams();

I get a vague error that says:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 515 General SQL Server error: Check messages from the SQL Server [515] (severity 16) [(null)]' in /var/www/html/sasite/GANT/mssql.php:308 Stack trace: #0 /var/www/html/sasite/GANT/mssql.php(308): PDOStatement->execute() #1 {main} thrown in /var/www/html/sasite/GANT/mssql.php on line 308

308 being "$karsyn->execute();"

It doesn't seem like you can "echo" a query in PDO so when you get an error, it's hard to know where to even begin.

How can I better troubleshoot what the problem is and what is the problem? I've broken it down to just one parameter and it still doesn't work.

Thoughts?
Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bruce GustPHP DeveloperAuthor Commented:
In an effort to better "see" what I'm doing, I did this:

$stunt_query = "insert into #gant_rows (tool_id) VALUES ('$michelle_row[int_DEVELOPERS_Tool_Id]')";
echo $stunt_query;

...and I got:

insert into #gant_rows (tool_id) VALUES ('1')
Bruce GustPHP DeveloperAuthor Commented:
Just for grins, to try and figure out what I'm dealing with, I did this:

      $sql_50="delete from gant_rows";
            $mssql_stmt_50=$mssql_pdo->prepare($sql_50);
            $mssql_stmt_50->execute();

How much more basic can it be?

I get this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 229 General SQL Server error: Check messages from the SQL Server [229] (severity 14) [(null)]' in /var/www/html/sasite/GANT/mssql.php:226 Stack trace: #0 /var/www/html/sasite/GANT/mssql.php(226): PDOStatement->execute() #1 {main} thrown in /var/www/html/sasite/GANT/mssql.php on line 226

#226 being $mssql_stmt_50->execute();

What's wrong?
Bruce GustPHP DeveloperAuthor Commented:
By the way, I set up gant_rows as a regular table in the database. I can run "delete from gant_rows" in MSSQL Studio and it runs fine.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Bruce GustPHP DeveloperAuthor Commented:
I tried this:

      $sql_50="TRUNCATE TABLE gant_rows";
            //$mssql_stmt_50=$mssql_pdo->prepare($sql_50);
            //$mssql_stmt_50->execute();
            $mssql_pdo->query($sql_50);

..and I get the same error: Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1088 General SQL Server error: Check messages from the SQL Server [1088] (severity 16) [TRUNCATE TABLE gant_rows]' in /var/www/html/sasite/GANT/mssql.php:227 Stack trace: #0 /var/www/html/sasite/GANT/mssql.php(227): PDO->query('TRUNCATE TABLE ...') #1 {main} thrown in /var/www/html/sasite/GANT/mssql.php on line 227

This is killing me! What am I missing?
Dan CraciunIT ConsultantCommented:
Looking at error codes, looks like a permission problem: 229 is permission denied.

229      14      %ls permission denied on object '%.*ls', database '%.*ls', owner '%.*ls'.

And 515 is: Cannot insert the value NULL into column '%.*ls', table '%.*ls'; column does not allow nulls. %ls fails.

HTH,
Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bruce GustPHP DeveloperAuthor Commented:
Dan, you nailed it!

I found out the following morning, after having posted this question, that my connection was based on a user distinct from myself. So while I could run the code in MSSQL Studio with no problem, running it from the web was a dealbreaker.

Thanks!
Dan CraciunIT ConsultantCommented:
You're welcome.

Glad I could help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.