sqlsrv UPDATE statement runs but doesn't update DB

余生颓废 提交于 2020-01-06 03:10:50

问题


I have an issue where my PHP sqlsrv UPDATE statement runs and doesn't return any errors but nothing in the DB ever changes and the row is not actually updated. Is there something I am missing that would allow this query to appear to run successfully but not update the row?

I have checked that the update statement runs in SQL server management studio and it updates the row.

$visitquery = "UPDATE tblVisit SET CalledInBy='WINNER' WHERE VisitID='3679061'";            

                    $visitClose = sqlsrv_prepare($connect,$visitquery);
                    if( sqlsrv_execute( $visitClose))
                        {
                              echo "Statement executed.\n <br />";
                        }
                        else
                        {
                             echo "Error in executing statement.\n";
                             die( print_r( sqlsrv_errors(), true));
                        } 

回答1:


Thanks @JonathanAmend

sqlsrv_begin_transaction was opened but wasn't calling sqlsrv_commit.

http://www.php.net/manual/en/function.sqlsrv-commit.php




回答2:


Make sure that your script has permission to access the correct database or nothing will happen to the tables.

So first, establish a connection to the database then specify the database that contains your table.

In your setup, add this line above your code.

$connect = sqlsrv_connect(server format goes here,array("Database"=>name of database containing tblVisit in quotes goes here,"UID"=>username to access database goes here,"PWD"=>password to access database goes here));

For each value, enclose them with quotes since they are strings.

There is more information on how to make the code here:

See this (at php.net)



来源:https://stackoverflow.com/questions/23740480/sqlsrv-update-statement-runs-but-doesnt-update-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!