Unable to connect To Database...PostgreSQL and PHP


Read With Formatting | Free Open Source Tutorials Account

PostgreSQL
Thread: Unable to connect To Database...PostgreSQL and PHP


manashi_130582
hi...
I am doin my project in PHP with PostgreSQL as backend...
Both r very new to me....
My OS is LINUX
when I am trying to connect to the database but its not getin connected...:confused:
By using
"su postgres" command
i hav created user "root" and database "sample"
By using
"psql -U root sample" command
i hav created table "login" and inserted 3 data's...
Now through code in PHP i am trying to insert the data but data is not getin inserted
the code is as follows :-

<?php
require_once "DB.php";
$uname=$_POST['uname'];
$pass=$_POST['pass'];

$username="root";
$password="";
$hostname="localhost";
$dbname="sample";

$db=new DB;
$dsource=$db->factory("pgsql");

$dcon=pg_connect("dbname=sample user=root");

$sql="insert into login values('$uname','$pass')";

$rs=$dsource->pg_query($sql);
?>


is there anythin wrong with the code or sum other problem
waiting for the reply... :)

pruthvi
hi,

this link might help you

http://us3.php.net/pgsql

regards

Pruthvi R