PHP delete record from postgresql table php - Net-Raft.com

Welcome aboard! We are happy you are here and wish you good net-raft!




Just a Web Code Solution
join us

How to delete a record from postgresql table using php ?


 49

PHP


1


<?php

$host = "host=xxx";
$port = "port=xxx";
$dbname = "dbname=xxx";
$credentials = "user=xxx password=xxx";

$db = pg_connect( "$host $port $dbname $credentials" );
if(!$db){
echo "Error : Unable to open database\n";
} else {
echo "Opened database successfully\n";
}

$sql =<<<EOF
DELETE from SALARIES where ID=2;
EOF;
$ret = pg_query($db, $sql);
if(!$ret){
echo pg_last_error($db);
exit;
} else {
echo "Record deleted successfully\n";
}

$sql =<<<EOF
SELECT * from SALARIES;
EOF;

$ret = pg_query($db, $sql);
if(!$ret){
echo pg_last_error($db);
exit;
}
while($row = pg_fetch_row($ret)){
echo "ID = ". $row[0] . "\n";
echo "NAME = ". $row[1] ."\n";
echo "ADDRESS = ". $row[2] ."\n";
echo "SALARY = ".$row[4] ."\n\n";
}
echo "Operation done successfully\n";
pg_close($db);

?> 


By        
The power of the user (%)
17%



The most helpful PHP solutions

detect browser phpdetect browser phpPHP

Click to see more ...

  4.6K     408

create QR code phpcreate QR code phpPHP

Click to see more ...

  3K     289

create relative date phpcreate relative date phpPHP

Click to see more ...

  2.2K     264

drag and drop upload file using phpdrag and drop upload file using phpPHP

Click to see more ...

  2.7K     253

delete array item phpdelete array item phpPHP

Click to see more ...

  2.4K     245

detect ie phpdetect ie phpPHP

Click to see more ...

  1.6K     213

detect speed internet phpdetect speed internet phpPHP

Click to see more ...

  1.6K     198

get current url phpget current url phpPHP

Click to see more ...

  1.7K     197

get meta tag phpget meta tag phpPHP

Click to see more ...

  1.4K     193

Get real client country using php ?Get real client country using php ?PHP

Click to see more ...

  1.4K     181

Welcome aboard!
We are happy you are here and
wish you good net-raft!