Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php pdo Check if row exists in the database

$stmt = $conn->prepare('SELECT * FROM table WHERE ID=?');
$stmt->bindParam(1, $_GET['id'], PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);

if( ! $row)
{
    echo 'nothing found';
}

/*
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // Same here
if( ! $rows)
{
    echo 'nothing found';
}
*/
Comment

pdo php check if row exist

$sql = 'SELECT 1 from table WHERE id = ? LIMIT 1';
//$sql = 'SELECT COUNT(*) from table WHERE param = ?'; // for checking >1 records
$stmt = $conn->prepare($sql);
$stmt->bindParam(1, $_GET['id'], PDO::PARAM_INT);
$stmt->execute();

if($stmt->fetchColumn()) echo 'found';
Comment

PREVIOUS NEXT
Code Example
Php :: delete in wordpress query 
Php :: php get random value from array 
Php :: laravel 8 $request-intersect not working 
Php :: codeigniter query builder order by 
Php :: laravel php 8 ububtu 
Php :: make model -mcr laravel 
Php :: wp display custom fields 
Php :: swich in php 
Php :: php remove specific element from array 
Php :: change php version using htaccess 
Php :: laravel generate unique token 
Php :: php serialize 
Php :: php date fomat 
Php :: wp revisions config 
Php :: woocommerce add custom field data to cart page 
Php :: set image asset path in laravel 
Php :: laravel db::query update 
Php :: group array php by key 
Php :: eloquent get query log 
Php :: check file selected in php 
Php :: php keep only letters and numbers 
Php :: replace all numbers in string php 
Php :: Merge Cell phpoffice phpexcel 
Php :: how to get the average in sql in php 
Php :: strtoupper 
Php :: php hash password using bcrypt 
Php :: route params link laravel 
Php :: laravel RuntimeException Session store not set on request. 
Php :: laravel 8 date format 
Php :: php get text from html 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =