Is the horror the global variables? The lack of enums for your switch statement? The inlined debugging print statements? The completely useless error message? The inefficiency of calling the database a single time for each column?
(I mean, good for you for using prepared statements… thank god).
Nah, all ORMs are bad. You always have to learn the ORM syntax plus you always drop down to sql for some things eventually. So you end up with a leaky abstraction that doesn’t actually abstract.
I’ve never seen an ORM project not play out that way.
Yeah because hand generating a huge SQL query is so much better and safer you know.
In our project with 90k lines of application code there are maybe 4 sqls, one of which I'd consider complex, everything else is handled by the orm with no issues.
function updateDB($column, $value) {
global $db;
global $ps;
switch ($column) {
case 'level':
$ps = $db->prepare("UPDATE USERS SET levels =? where USERS.`id`=?");
/* print("level"); */
break;
case 'notes':
$ps = $db->prepare("UPDATE USERS SET notes =? where USERS.`id`=?");
/* print("notes"); */
break;
default:
print("error");
break;
}
5
u/TheBrainStone Jan 03 '23
What's the bug?
61
u/ddruganov Jan 03 '23
Oh no, the issue is absolutely not the php8.1 bug but apparently its your whole fucking codebase
13
u/[deleted] Jan 03 '23
Always love it when people post their own code to r/badcode lol
23
u/SeesawMundane5422 Jan 03 '23
Is the horror the global variables? The lack of enums for your switch statement? The inlined debugging print statements? The completely useless error message? The inefficiency of calling the database a single time for each column?
(I mean, good for you for using prepared statements… thank god).
9
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 03 '23
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
4
u/Teriuihi_ Jan 03 '23
is case 'level' supposed to update column levelS?
3
u/Paul_Robert_ Jan 03 '23
I like that color theme, what's it called?
2
u/No_Soy_Colosio Jan 04 '23
As soon as I saw global I realized it was bad code
-13
u/Quito246 Jan 03 '23
Classical PHP either buggy or deprecated 🤣