pdo php fetch return one result code example
Example 1: php pdo fetch from db
$dbhost = @mysql_connect($host, $user, $pass) or die('Unable to connect to server');
@mysql_select_db('divebay') or die('Unable to select database');
$search = $_GET['searchdivebay'];
$query = trim($search);
$sql = "SELECT * FROM auction WHERE name LIKE '%" . $query . "%'";
if(!isset($query)){
echo 'Your search was invalid';
exit;
}
$result = mysql_query($trim);
$numrows = mysql_num_rows($result);
mysql_close($dbhost);
Example 2: how to fetch data using pdo in php
$stmt = $pdo->prepare("SELECT * FROM users LIMIT :limit, :offset");$stmt->execute(['limit' => $limit, 'offset' => $offset]); $data = $stmt->fetchAll();