php - Protecting mysql database from injection attacks with pdo script -
recently, database experienced attack mysql injections. did not know injections before incident. however, have been studying on , how prevent it, cannot seem work script when try add sql injection protection (it works fine on it's own). how pdo script add sql injection protection?
<?php $username = $_get["hits"]; $sq = "something"; $pu = $_get["something"]; $jjj = "something"; $fff = "something"; $dbh = new pdo("mysql:host=$sq;dbname=$pu", $jjj, $fff); $sql = 'select autoj tabl username = ?'; $params = array( $username ); if ( isset( $_get['q'] ) ) { $sql .= " , myname ?"; $params []= '%'.$_get['q'].'%'; } $q = $dbh->prepare( $sql ); $q->execute( $params ); $doc = new domdocument(); $r = $doc->createelement("mutablerec" ); $doc->appendchild( $r ); foreach ( $q->fetchall() $row) { $e = $doc->createelement( "mutablerec" ); $e->setattribute( 'autoj', $row['autoj'] ); $r->appendchild( $e ); } print $doc->savexml(); ?>
edit: appears prepare , execute should prevent me. however, need include: $pdo->setattribute(pdo::attr_emulate_prepares, false);
Comments
Post a Comment