Thread: Database connection

Database connection

From
"Jill Jensen"
Date:
Hello:

I cannot connect to my database::

the code is this:


<html>
<body>
<?php



$host = "localhost";
$user = "srproject";
$pass = "56364563";
$db = "srproject";

//open a connection to the database server
$connection = pg_connect ("host=$local host dbname=$srproject
user=$srproject password=$56364563");

$connection = pg_connect ("host=$host dbname=$dbuser=$user password=$pass");

if (!$connection)
{
    die("Could not open connection to database server");
}

$query = "INSERT INTO student(firstname, lastname) VALUES ('jill',
'jensen')";


if (!$result) {
printf ("ERROR");
$errormessage = pg_errormessage($db);
echo $errormessage;
exit;
}
printf ("These values were inserted into the database - %s %s", $firstname,
$lastname);
pg_close();
?>
</body>
</html>

-------------------------------------

the error I get is this:

Warning: pg_connect() unable to connect to PostgreSQL server: unknown host
name: host in /home/srproject/webpage/action.php on line 13

Warning: pg_connect() unable to connect to PostgreSQL server: could not
connect to server: Connection refused Is the server running on host
localhost and accepting TCP/IP connections on port 5432? in
/home/srproject/webpage/action.php on line 15
Could not open connection to database server

I have been assure that port 5432 is open for connections on the localhost,
and that tcp/ip connections are accepted.
Best regards,

Jill Jensen, MCP
Operations Manager


jill.jensen@aisn.net

AIS Network
Internet Services Worldwide
http://www.aisn.net

Office:  847. 202. 1400   x 27
Fax:      847-202-4460
Cell:     847. 530. 7845



Re: Database connection

From
Tom Lane
Date:
"Jill Jensen" <jill.jensen@aisn.net> writes:
> $host = "localhost";
> $user = "srproject";
> $pass = "56364563";
> $db = "srproject";

> //open a connection to the database server
> $connection = pg_connect ("host=$local host dbname=$srproject
> user=$srproject password=$56364563");

This is surely wrong.

> $connection = pg_connect ("host=$host dbname=$dbuser=$user password=$pass");

This looks reasonable except you need another space:

$connection = pg_connect ("host=$host dbname=$db user=$user password=$pass");

            regards, tom lane

Re: Database connection

From
"paul butler"
Date:
Send reply to:      <color><param>0000,0000,8000</param><<jill.jensen@aisn.net>

</color>From:               <color><param>0000,0000,8000</param>"Jill Jensen" <<jill.jensen@aisn.net>

</color>To:                 <color><param>0000,0000,8000</param><<pgsql-novice@postgresql.org>

<bold></color>Subject:            <color><param>0000,0000,8000</param>[NOVICE] Database connection

</bold></color>Date sent:          <color><param>0000,0000,8000</param>Sun, 26 Jan 2003 19:03:08 -0600


There's a php pg list somewhere for these questions, I've outlined
what I think is wrong below</color>



<color><param>7F00,0000,0000</param>> Hello:

>

> I cannot connect to my database::

>

> the code is this:

>

>

> <<html>

> <<body>

> <<?php

>

>

>

> $host = "localhost";

> $user = "srproject";

> $pass = "56364563";

> $db = "srproject";

>

> //open a connection to the database server



</color>Theres a space in $local host here, so $local host will evaluate to
something useless like "" or Null >>



<color><param>7F00,0000,0000</param>> $connection = pg_connect ("host=$local host dbname=$srproject

> user=$srproject password=$56364563");



</color>why are you redelaclaring the connection parameters here ?(and thanks to the above line $host will not evaluate
usefully)>>



<color><param>7F00,0000,0000</param>> $connection = pg_connect ("host=$host dbname=$dbuser=$user

> password=$pass");

>

> if (!$connection)

> {

>  die("Could not open connection to database server");

> }

>

> $query = "INSERT INTO student(firstname, lastname) VALUES ('jill',

> 'jensen')";

>

>

> if (!$result) {

> printf ("ERROR");

> $errormessage = pg_errormessage($db);

> echo $errormessage;

> exit;

> }

> printf ("These values were inserted into the database - %s %s",

> $firstname, $lastname); pg_close(); ?> <</body> <</html>

>

> -------------------------------------

>

> the error I get is this:

>

> Warning: pg_connect() unable to connect to PostgreSQL server: unknown

> host name: host in /home/srproject/webpage/action.php on line 13

>

> Warning: pg_connect() unable to connect to PostgreSQL server: could

> not connect to server: Connection refused Is the server running on

> host localhost and accepting TCP/IP connections on port 5432? in

> /home/srproject/webpage/action.php on line 15 Could not open

> connection to database server

>

> I have been assure that port 5432 is open for connections on the

> localhost, and that tcp/ip connections are accepted. Best regards,

>

> Jill Jensen, MCP

> Operations Manager

>

>

> jill.jensen@aisn.net

>

> AIS Network

> Internet Services Worldwide

> http://www.aisn.net

>

> Office:  847. 202. 1400   x 27

> Fax:      847-202-4460

> Cell:     847. 530. 7845

>

>

>

> ---------------------------(end of

> broadcast)--------------------------- TIP 4: Don't 'kill -9' the

> postmaster

</color>HTH


Paul Butler

<nofill>

Re: Database connection

From
"Jill Jensen"
Date:
Hi Tom:

Thanks for the help.

Best regards,

Jill Jensen, MCP
Operations Manager


jill.jensen@aisn.net

AIS Network
Internet Services Worldwide
http://www.aisn.net

Office:  847. 202. 1400   x 27
Fax:      847-202-4460
Cell:     847. 530. 7845


-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Wednesday, January 29, 2003 1:02 AM
To: jill.jensen@aisn.net
Cc: pgsql-novice@postgresql.org
Subject: Re: [NOVICE] Database connection


"Jill Jensen" <jill.jensen@aisn.net> writes:
> $host = "localhost";
> $user = "srproject";
> $pass = "56364563";
> $db = "srproject";

> //open a connection to the database server
> $connection = pg_connect ("host=$local host dbname=$srproject
> user=$srproject password=$56364563");

This is surely wrong.

> $connection = pg_connect ("host=$host dbname=$dbuser=$user
password=$pass");

This looks reasonable except you need another space:

$connection = pg_connect ("host=$host dbname=$db user=$user
password=$pass");

            regards, tom lane