sql server - PHP - PDO - MSSQL and Deleting with apostrophes -


i have read posts can apostrophes , i'm still in dark. in code i'm trying delete record contains apostrophe , space. can't delete. code works fine unless there apostrophe. i'm working in php/dbo working mssql database. i've deleted password , username sample code.

    <?php      $attrs = array(pdo::attr_persistent => true);     $pdo = new pdo("dblib:host=server;dbname=aer;charset=utf8", "", "");     $pdo->exec('set character set utf8');      $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception);      $teststring="tom's tom";     $teststring = str_replace("'", "''", $teststring) ;     try {         $stmt = $pdo->prepare('delete jno_clubs club = :id');         $stmt->bindvalue(':id',$teststring, pdo::param_str);         $stmt->execute();             } catch(pdoexception $e) {      echo 'error: ' . $e->getmessage();     }     ?> 

i've tried , without line:

$teststring = str_replace("'", "''", $teststring) ; 

if can i'd grateful.

i don't think need replace apostrophe double apostrophes:

$teststring="tom's tom";  $teststring = str_replace("'", "''", $teststring) ;  try {     $stmt = $pdo->prepare('delete jno_clubs club = :id');     $stmt->bindvalue(':id',$teststring, pdo::param_str); 

because i'd wager call bindvalue take care of you. it's execution of statement passing "tom''''s tom" in value of :id. try removing call str_replace.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -