So recently I heard PDO actually isn't safe unless you know exactly what you're doing, or in my case, copy/pasting. Not only that, I didn't know you can't trust your own database either from an attack.. So well, it doesn't feel too right to ask what I'm asking, but I need to make sure I'm safe before it's too late. Not only that, I'm making a game website where users can save their games and when you lose save game data, a lot of us know that it really really sucks. Here is what my PDO connection currently looks like:
$DataB = new PDO( 'mysql:dbname = dbname; host = host.host.host; charset = utf8', 'username', 'password' );
$DataB -> setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
$DataB -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
Honestly, all I know is that it's PDO, and works. Is this pretty much safe to use if I don't change it? Also, what about when I'm inserting data? Well, like this:
$a = $DataB -> prepare( "INSERT INTO `names` (`first`,`last`) VALUES (?,?)" );
$a -> execute( array( $FirstName, $LastName ) );
Now to be honest I'm not too sure if I wrote that correctly, but thats only because I have it in a personal function I made and it would take awhile before I can decode it (the same with the following below too). Now for updating, I've been using this:
$DataB -> prepare( "UPDATE `names` SET :fn WHERE id = :a" ) -> execute( array( ':a' => $IDnumber, ':fn' => $NewFname ) );
which is kind of the same, but it works on one line. I'm not sure if it matters, but I'm not a genius. But I always prefer shorter codes when possible. Now my select one:
$a = $DataB -> prepare( "SELECT * FROM `names` WHERE `password` = :pw AND `email` = :e " );
$a -> execute( array( ':pw' => $_COOKIE['password'], ':e' => $_COOKIE['email'] ) );
while ( $b = $a -> fetch( PDO::FETCH_ASSOC ) ) { $Fname = $b['first'] }
echo $Fname;//<-filtered html in real life
Which makes me wonder if there's any filters I'm missing for the PDO's I have, since I heard I can't trust my own database either. Now, that's pretty much my database user stuff with nothing extra missing (well, nothing important missing). And yes I have read this on this website which sort of says you can't prevent a certain attack before PHP 5.3.6, but my website only has PHP 5.3.0. Or, that's what a live person I just asked said. But still, I'm not certain if how I use my database is even the proper way to use it. For when I insert, update, and select/other user made data when who knows what it looks like.
So long story short, I need to make sure this works in PHP 5.3.0. And doesn't mess up anything important with random user made data.