pdo_stored_func3.htm
pdo_stored_func3.htm same as pdo_stored_func4.htm
Get Only One Row:

/* Fetch only the first row from the results */
	$result= $stmt->fetch();
	echo "29.25<sup>o</sup>C  = ".$result[0]." <sup>o</sup>F "; 
	echo "<br/>db closed "; 
   /*** close the database connection ***/
   $dbconn= null;
}

 

Code

<?php
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'Manas9';
/* dbname */
$db = "test";
/*** mysql password ***/
$password = 'Manas9237';

try {

$dbconn= new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
/*** echo a message saying we have connected ***/
echo 'Retreive of MySQL stored function with PDP <br />';
echo 'Connected to database <br />';
/*** The SQL SELECT statement ***/
//$sql = "SELECT * FROM emp1 ORDER BY fname";
$sql= "SELECT ctof(29.25)";
echo" fetch into an PDOStatement object <br/>";
$stmt = $dbconn->prepare($sql);
$stmt->execute();

/* Fetch only the first row from the results */
$result= $stmt->fetch();
echo "29.25<sup>o</sup>C = ".$result[0]." <sup>o</sup>F ";
echo "<br/>db closed ";
/*** close the database connection ***/
$dbconn= null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
 

Displaying with Firefox brwser: