3 ms·
For scripts I use Python, but I like to use PHP for short quick scripts when a database is involved since all it takes is to install php and php-pdo to have a c
by candl 3y ago
For scripts I use Python, but I like to use PHP for short quick scripts when a database is involved since all it takes is to install php and php-pdo to have a consistent api for db access to get started with, which for python is not the case.
But from time to time I am reminded how bad PHP and outright dangerous can be. Just the other day I had an array like this: ["123"=>"foo", "321" => "bar"] on which I used array_keys expecting to get ["123", "321"] as a result. Surprised why my script was not working the way it was supposed to I found out that the result was actually [123, 321] instead. Yep, PHP casts strings to numbers in this case when it can. I will hit a "gem" like this every now and then, there are plenty of such dumb things scattered in PHP that will bite you the least expected way that makes me stop and think to use something else.
- drcongo 3y ago> all it takes is to install php and php-pdo to have a consistent api for db access to get started with, which for python is not the case What's the difference between that and `pip install psycopg2` (which actually seems easier to me)?
- candl 3y agopdo is a common interface layer for databases for php, like jdbc in java or ado.net in C# so I can use the same api for any supported database. In python technically dbapi standard exists for the same task, but the driver apis annoyingly vary so much between themselves that if i have to i go with sqlalchemy, but it's no longer a lightweight solution
- drcongo 3y agoThat makes sense, thanks. It seems I somehow forgot that databases other than Postgres exist.