php pdo check if record exists before insert

Solutions on MaxInterview for php pdo check if record exists before insert by the best coders in the world

showing results for - "php pdo check if record exists before insert"
Loanne
07 Nov 2017
1$sql = $dbh->prepare("SELECT COUNT(*) AS `total` FROM directory WHERE telephone = :phone");
2$sql->execute(array(':phone' => $telephone));
3$result = $sql->fetchObject();
4
5if ($result->total > 0) 
6{
7    echo 'The telephone number: ' . $telephone. ' is already in the database<br />';
8}
9else 
10{
11      echo 'No rows matched the query.';
12}
13
Ilona
18 Jul 2017
1ALTER TABLE `requests` ADD UNIQUE `imdbid_unique`(`imdbid`);
2
Finn
06 Jan 2018
1REPLACE INTO ***** SET name = ?, slideView = ?, company = ?