I am just switching my queries from mysql_ to PDO as well. Rather than just telling you to change, I will try my best to get it right in PDO... if I mess up, I will learn something. Hopefully, you can take that and build from it and improve what you are doing as I continue to improve my queries. I only have one small app upgraded with a few big ones to go. Still in learning phase.
I will be honest, I never would have upgraded if I haven't gotten on stack overflow all the time now. Every person who uses the mysql_connect gets hit on it. Made me get outside of my little programmer box and notice. Thanks guys!
OK, I am about to mess this up, so don't laugh.
P.S. Can't believe no one mentioned the Table in the question. What happens if more than one product has the same name?
$stmt=$con->prepare("SELECT * FROM results WHERE prodnam=:pnam"); // named variables in prepared
$stmt->bindValue(':pnam', $pnam, PDO::PARAM_STR); // bind it to the variable
$stmt->execute();
$hit = $stmt->rowCount(); // count them rows
if($hit) {
while($results = $stmt->fetchAll(PDO::FETCH_ASSOC)) {
echo $results['dtlsnam'];
/* I ignored the fact you are using tables because maybe it is a good tabular layout
* you are planning. You can figure out the table part. But best to loop and put the table
*start before the loop and the table end after the loop and just loop the rows.
*/
}
}
//
// Then in your connection include you want something like this.
//
// put in the values for your variables.
<?php
try {
$con = new PDO("mysql:host=" . $DB_MYSQL_HOST. ";dbname=" . $DB_MYSQL_NAME, $DB_MYSQL_USER, $DB_MYSQL_PASS);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>