Backboards: 
Posts: 153
In response to "So ... while paralyzed by database interaction choices last night, I definitely learned one thing." by Beryllium

This post looks better when viewed on the beta site, FWIW -- (link)

(No message)


So ... while paralyzed by database interaction choices last night, I definitely learned one thing.
Beryllium (aka grayman) Sep 26 '13, 08:22
(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: [code] UPDATE tablename SET columnname = ? WHERE id = ?; [/code] And then you have to replace the question marks using a call like this (if the id is "5", for example): [code] $query->bindParams('sd', [ 'NewColumnValue', 5] ); $query->execute(); [/code] Doing it with PDO was much nicer: [code] UPDATE tablename SET columnname = :columnvalue WHERE id = :row_id; [/code] and [code] $stmt->execute(['columnvalue'=>'NewColumnValue','row_id'=>5]); [/code] 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.