This is my code to count number of rows in PHP PDO
$sql = "SELECT count(name) FROM `info` WHERE name='$name' "; 
$result = $conn->prepare($sql); 
$result->execute(); 
$totalrows = $result->fetchColumn(); 
But the problem is, If the $name contain an ', it gives error. Prepared statement is fast, secure and better. How to convert it into prepared statement?
I tried to make it PHP PDO statement, but it is not working
$stmt = $conn->prepare("SELECT count(name) FROM `info` WHERE name='$name' "); 
$stmt->execute(array('name' => $name));
$totalrows = $stmt->fetchColumn(); 
