Backboards: 
Posts: 153

So ... while paralyzed by database interaction choices last night, I definitely learned one thing.

(What I already knew:)

There are three types of MySQL database access baked into PHP. A library of functions called "mysql_*" (they are outdated & dangerous), a library of functions/objects called "mysqli_*" (they are less-outdated and slightly safer), and "PDO", which is pretty powerful and allows you to abstract database access stuff.

(What I learned)
mysqli_* prepared statements are *ass*. When writing an update query in a prepared statement, it looks like this:

UPDATE tablename SET columnname = ? WHERE id = ?;


And then you have to replace the question marks using a call like this (if the id is "5", for example):

$query->bindParams('sd', [ 'NewColumnValue', 5] );
$query->execute();


Doing it with PDO was much nicer:

UPDATE tablename SET columnname = :columnvalue WHERE id = :row_id;


and

$stmt->execute(['columnvalue'=>'NewColumnValue','row_id'=>5]);


The ability to name columns like that is so much easier to maintain, especially in complicated queries.


Responses:
Post a message   top
Replies are disabled on threads older than 7 days.