Database Connection
Database Connection
txt Page 1 of 2
postgres=# \l
postgres=# \c Ankita;
You are now connected to database "Ankita" as user "postgres".
Ankita=# CREATE TABLE student(roll_no int primary key, Name varchar(20));
CREATE TABLE
Ankita=# select * from student;
roll_no | name
---------+------
(0 rows)
<?php
$host="localhost";
$user="postgres";
$pass="password";
$db="Ankita";
$rows=pg_num_rows($result);
echo "There are currently $rows records in database.<br>";
pg_close($con);
File: /home/smj/Downloads/database_connection.txt Page 2 of 2
?>
O/P :
Connection succes
There are currently 3 records in database.
<?php
$host="localhost";
$user="postgres";
$pass="password";
$db="Ankita";
$rows=pg_num_rows($result);
echo "There are currently $rows records in database.<br>";
if($rows>0)
{
for($i=0;$i<$rows;$i++)
{
$row=pg_fetch_row($result,$i);
echo $row[0] ."<br>". $row[1] ."<br>". $row[2];
}
}
else
{
echo"No data Available";
}
pg_close($con);
?>