Answers for "php pdo Check if row exists in the database"

PHP
0

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.';
}
Posted by: Guest on October-01-2021
0

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';
}
*/
Posted by: Guest on October-16-2021
0

php pdo check if record exists before insert

ALTER TABLE `requests` ADD UNIQUE `imdbid_unique`(`imdbid`);
Posted by: Guest on October-01-2021

Code answers related to "php pdo Check if row exists in the database"

Browse Popular Code Answers by Language