Search
 
SCRIPT & CODE EXAMPLE
 

PHP

pdo php check if row exist

$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

php pdo check if record exists before insert

$sql = $dbh->prepare("SELECT COUNT(*) AS `total` FROM directory WHERE telephone = :phone");
$sql->execute(array(':phone' => $telephone));
$result = $sql->fetchObject();

if ($result->total > 0) 
{
    echo 'The telephone number: ' . $telephone. ' is already in the database<br />';
}
else 
{
      echo 'No rows matched the query.';
}
Comment

php pdo check if record exists before insert

ALTER TABLE `requests` ADD UNIQUE `imdbid_unique`(`imdbid`);
Comment

PREVIOUS NEXT
Code Example
Php :: select tag in laravel collective 
Php :: codeigniter form_validation email 
Php :: Magento 2 -Limit the length of the product name on the front end. 
Php :: wordpress throw to debug.log 
Php :: remove link from product name in woocommerce cart 
Php :: get the last saved row in a table laravel 
Php :: closing a php 
Php :: convert json object to array in php 
Php :: php get timezone 
Php :: disable block editor on widget section wordpress 
Php :: php why " " not new line 
Php :: serialize() php 
Php :: console php 
Php :: how to create compomemt in laravel livewire 
Php :: laravel migration add date of birth column 
Php :: laravel auth ui command 
Php :: datediff in hour query builder laravel 
Php :: laravel validation allow empty array 
Php :: php artisan route:list for specific name 
Php :: how to return variable from transaction laravel 
Php :: php string only letters 
Php :: get categories wordpress query 
Php :: format datetime ISO php 
Php :: get post by taxonomy 
Php :: PHP strtoupper() Function 
Php :: laravel instal 
Php :: format date in laravel using carbon 
Php :: php for loop 
Php :: laravel drop column 
Php :: laravel curl request 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =