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

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -