473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

No connection with database


I want store data in 2 different database, just for backup. One database
is located at the webserver, the 2nd one on another server.

I've writte this little script to test it.

<?php
$db1 = pg_connect("host=123.123.123.123 dbname=test user=usrphp");
$cmd = "insert into website (ipnr, page) values ('777', 'main')";
$result = pg_query($db1, $cmd);

$db2 = pg_connect("dbname=test user=usrphp");
$cmd = "insert into website (ipnr, page) values ('777', 'main')";
$result = pg_query($db2, $cmd);

echo ($db1);
echo ("\n");

echo ($db2);
echo ("\n");

pg_close($db1);
pg_close($db2);

?>

When I call this script from the command prompt, I get the result:

Resource id #1
Resource id #3

and the data is written to both databases.

When I call the script with a browser from outside, I get the result:

Resource id #2

Data is written only to the local database.

Why ?
Many thanks in advance.

Joachim
Nov 24 '06 #1
5 1489
Joachim Smit wrote:
>
I want store data in 2 different database, just for backup. One database
is located at the webserver, the 2nd one on another server.

I've writte this little script to test it.

<?php
$db1 = pg_connect("host=123.123.123.123 dbname=test user=usrphp");
$cmd = "insert into website (ipnr, page) values ('777', 'main')";
$result = pg_query($db1, $cmd);

$db2 = pg_connect("dbname=test user=usrphp");
$cmd = "insert into website (ipnr, page) values ('777', 'main')";
$result = pg_query($db2, $cmd);

echo ($db1);
echo ("\n");

echo ($db2);
echo ("\n");

pg_close($db1);
pg_close($db2);

?>

When I call this script from the command prompt, I get the result:

Resource id #1
Resource id #3

and the data is written to both databases.

When I call the script with a browser from outside, I get the result:

Resource id #2

Data is written only to the local database.

Why ?
Many thanks in advance.

Joachim
Which is just what should happen.

When you run it from the command line on your machine, $db2 will be a
connection to your machine, because that's where the PHP is running.

When you execute it from a browser, the script is being executed by the
server, and $db2 would point to a database one the server - which would
be something entirely different.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 24 '06 #2
>
Which is just what should happen.

When you run it from the command line on your machine, $db2 will be a
connection to your machine, because that's where the PHP is running.

When you execute it from a browser, the script is being executed by the
server, and $db2 would point to a database one the server - which would
be something entirely different.
There is no difference between my machine and the server. I run the
script from the command prompt on the server. In both cases the same
script runs on the same server. The only difference is the way I call
the script.

Joachim
Nov 24 '06 #3
Joachim Smit wrote:
>>
Which is just what should happen.

When you run it from the command line on your machine, $db2 will be a
connection to your machine, because that's where the PHP is running.

When you execute it from a browser, the script is being executed by
the server, and $db2 would point to a database one the server - which
would be something entirely different.

There is no difference between my machine and the server. I run the
script from the command prompt on the server. In both cases the same
script runs on the same server. The only difference is the way I call
the script.

Joachim
Ok, then how about the user privileges? When you call it from the
browser you're running under a different ID than when you're calling
from the command line.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 25 '06 #4
Ok, then how about the user privileges? When you call it from the
browser you're running under a different ID than when you're calling
from the command line.
Does it make any difference?

iptables and pg_hba.conf are allright on the external server. I don't
need to make any changes there, I think.

What could I change on the internal server?

Joachim
Nov 25 '06 #5
Joachim Smit wrote:
>Ok, then how about the user privileges? When you call it from the
browser you're running under a different ID than when you're calling
from the command line.

Does it make any difference?

iptables and pg_hba.conf are allright on the external server. I don't
need to make any changes there, I think.

What could I change on the internal server?

Joachim
It sure can. This has nothing to do with iptables, pg_hba.conf or
anything similar.

There are many things which could be different. The userid is the
first; it could also be you're using a different version of PHP when
running through a web server vs. the command line, could be loading a
different pg library - a lot of things.

You need to find out what's different between the two. Because if the
environment were the same, the script would work the same.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: AMC | last post by:
Hi, I'm using an include file to store the connection string to a database. Whenever I try to reference that string to open a connection in the page that includes the file I get the error 'empy...
11
by: pradeep_TP | last post by:
Hi all, I have a few questions that I have been wanting to ask for long. These are all related to ADO.net and specifically to conenction to database. 1) If I have opened a connection to a...
3
by: R Reyes | last post by:
Hi, I'm trying to modularize my database connections a little better and get more out of my project with less code. First check out this common dbOpen() function inside class clsDatabase. I...
7
by: Lau Lei Cheong | last post by:
Hello, Actually I think I should have had asked it long before, but somehow I haven't. Here's the scenerio: Say we have a few pages in an ASP.NET project, each of them needs to connect to...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
35
by: Terry Jolly | last post by:
Web Solution Goal: Have a global database connection Why: (There will be 30+ tables, represented by 30+ classes) I only want to reference the database connection once. I put the connection...
6
by: Arsalan Ahmad | last post by:
Hi all, I am creating a website in which in an Item detail page there are a number of web controls (7 or 8) and what is happening that inside each of control's Page_Load() function I am creating...
5
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.