sqlsrv updates not working #46864
Unanswered
ChrisSantiago82
asked this question in
Q&A
Replies: 1 comment 2 replies
-
You have an extra space in '32862 ' at the end with a primary key declared as a string. Strings '32862 ' and '32862' won't match. Perhaps that's the reason. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a very strange issue with sqlsrv. Creating a new model and save it to the database works. Updating it, not anymore.
Query gets executed, without any errros, just the data are not being updated. Only way I could make it work if I interact directly with the pdo. Because of this, I think everything is set up correctly, with the odbc and the database settings. And retrieving data also works like a charm. Just updates won't happen.
I have tried the following:
$mitgliederstamm = Mitgliederstamm::findOrFail('32862 ');
$mitgliederstamm->AnredeID = 2;
$mitgliederstamm->save();
Mitgliederstamm::where('MitgliedsNr', '=', '32862 ')
->update(
[
'AnredeID' => 2,
]
);
DB::connection('sqlsrv')
->update(DB::RAW("UPDATE Mitgliederstamm SET AnredeID = 2 WHERE (MitgliedsNr = '32862 ')"));
Here with the raw query, if I build in a syntax error, I'm getting a syntax error from the database. That means it's talking to the database. It's just not updating the data.
$pdo = DB::connection('sqlsrv')->getPdo();
$query=$pdo->prepare("UPDATE Mitgliederstamm SET AnredeID = 2 WHERE (MitgliedsNr = '32862 ')");
$query->execute();
If I work directly with the pdo, then the same query works fine and the data is being updated.
That is how the model looks like:
class Mitgliederstamm extends Model
{
Does anybody has any idea?
Beta Was this translation helpful? Give feedback.
All reactions