473,586 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query problems with PostgreSQL

Hi,

I'm having intermittent problems with queries from my php script to a
postgresql database.

I have a form where I can enter a search query - for instance a last
name. This leads to a results page with a brief bit of information
about each of the matching results. From there, I can click a link
associated with any of the results which takes me to a page with all of
the details. Pretty standard stuff.

Problem I'm having is that for some of the results, when I click the
link to go to the full details page, no information is returned by the
script. I basically end up with my html template & no data populated.
For the majority of items, things work just fine.

One thing I've noticed is that it seems to be reproducable - that is,
for example item 5123 always fails to return any results on the full
details page.
>From my Postgres box (windows 2003), I can run the exact same query as
from my PHP script (with item id 5123) & it returns the data.

So what could the problem possibly be?

I thought that perhaps it was a load issue on the server - couldn't
answer the query, but the fact that it's reproducible seems to nix that
idea. Also, that Postgres box has 3.5 GB of RAM & we're talking about
a test system at this point - I'm the only one using it.

Code for my first search results page (basic info & hyperlinks) looks
like this ($name_last is the variable passed from the search form):

$connection=pg_ connect("host=1 0.10.10.2 port=5432 dbname=db1
user=dbuser password=passwo rd");

$myresult = pg_exec($connec tion, "SELECT identification_ no, name_last
, name_first, name_middle FROM public.j_identi fication WHERE name_last
~*
'$name_last'");
The code for my detailed results page looks like this:

$connection = pg_connect("hos t=10.10.10.2 port=5432 dbname=db1
user=dbuser password=passwo rd");

$myresult = pg_exec($connec tion, "SELECT * FROM
public.archived _with_photos
WHERE identification_ no = '$id_no'");
'public.archive d_with_photos' is a view defined on the postgresql
server.

I can run the query

SELECT * FROM public.archived _with_photos WHERE identification_ no =
'5123';

and it returns all of the associated data from the database... whereby
the exact same query failed with the PHP script.

Any help or ideas greatly appreciated!

Jan 10 '07 #1
2 2323
webhead74 wrote:
Hi,

I'm having intermittent problems with queries from my php script to a
postgresql database.

I have a form where I can enter a search query - for instance a last
name. This leads to a results page with a brief bit of information
about each of the matching results. From there, I can click a link
associated with any of the results which takes me to a page with all of
the details. Pretty standard stuff.

Problem I'm having is that for some of the results, when I click the
link to go to the full details page, no information is returned by the
script. I basically end up with my html template & no data populated.
For the majority of items, things work just fine.

One thing I've noticed is that it seems to be reproducable - that is,
for example item 5123 always fails to return any results on the full
details page.
>>From my Postgres box (windows 2003), I can run the exact same query as
from my PHP script (with item id 5123) & it returns the data.

So what could the problem possibly be?

I thought that perhaps it was a load issue on the server - couldn't
answer the query, but the fact that it's reproducible seems to nix that
idea. Also, that Postgres box has 3.5 GB of RAM & we're talking about
a test system at this point - I'm the only one using it.

Code for my first search results page (basic info & hyperlinks) looks
like this ($name_last is the variable passed from the search form):

$connection=pg_ connect("host=1 0.10.10.2 port=5432 dbname=db1
user=dbuser password=passwo rd");

$myresult = pg_exec($connec tion, "SELECT identification_ no, name_last
, name_first, name_middle FROM public.j_identi fication WHERE name_last
~*
'$name_last'");
The code for my detailed results page looks like this:

$connection = pg_connect("hos t=10.10.10.2 port=5432 dbname=db1
user=dbuser password=passwo rd");

$myresult = pg_exec($connec tion, "SELECT * FROM
public.archived _with_photos
WHERE identification_ no = '$id_no'");
'public.archive d_with_photos' is a view defined on the postgresql
server.

I can run the query

SELECT * FROM public.archived _with_photos WHERE identification_ no =
'5123';

and it returns all of the associated data from the database... whereby
the exact same query failed with the PHP script.

Any help or ideas greatly appreciated!
Strange.
I cannot imagine Postrgres will have problems with a certain
identification_ no.
It must be something else.
Did you turn on ALL errorreporting?
And what does $myresult contain?

Also pg_exec is very old. Avoid it.
php.net doesn't even list it anymore...
Start using pg_query instead.

Regards,
Erwin Moller
Jan 10 '07 #2
webhead74 wrote:
$myresult = pg_exec($connec tion, "SELECT * FROM
public.archived _with_photos
WHERE identification_ no = '$id_no'");
Could be something funny going on with the variable interpolation. Try:

$myquery = "SELECT *
FROM public.archived _with_photos
WHERE identification_ no = '$id_no'";
$myresult = pg_query($conne ction, $query);
var_dump(array( 'Q'=>$query, 'R'=>$myresult) );

Does the var_dump reveal the query you expected?

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 11 '07 #3

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

Similar topics

7
12056
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound to know this number after the first FETCH, isn't it? On a side note, why queries using LIMIT are SO terribly slow, compared to cursors and...
16
4186
by: Dave Weaver | last post by:
I'm having severe performance issues with a conceptually simple database. The database has one table, containing weather observations. The table currently has about 13.5 million rows, and is being updated constantly. (The database is running on a dual 550MHz PIII with 512MB RAM. I have PostgreSQL 7.1.3 on i686-pc-linux-gnu, compiled by GCC...
8
3244
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run simultaneously 4 similar queries it takes nearly 5 minutes instead of 4 times 9 seconds or something near of that. here is a sample query: select ...
1
3689
by: Dino Nardini | last post by:
Hey folks, I've been migrating a content management system from MS SQL Server 7 over to PostgreSQL. I used the EMS DataPump utility (http://www.ems-hitech.com/index.phtml) to migrate the database, but noticed that in the process it truncated a few large text blocks. I then plugged the ColdFusion web application into the PG database and...
3
3378
by: Stijn Vanroye | last post by:
Hi List, I'm running a query on a not-so-small db. Mostly this query runs fast enough, but every once in a while the query takes a long time to complete in wich case the users start banging away on the keyboard :-). What we would like to do is cancel the query after a certain time-out (e.g.30 sec.) Is there some way to send a command to...
2
3820
by: Keith C. Perry | last post by:
Ok, I've tried a number of things here and I know I'm missing something but at this point my head is spinning (i.e. lack of sleep, too much coffee, etc...) My environment is PG 7.4.3 on Linux with 512Mb of ram and swap. This was just upgraded from 7.4 (just to make sure I'm current). Some of my settings in postgresql are giving fatal...
11
6640
by: Tore Halset | last post by:
Hello. I am trying to port an old java application from MS SQL Server to PostgreSQL running on Mac OS X. I have access to the java source code and can make modifications. I have tried with PostgreSQL version 7.4.2 and 8.0.0beta2, but get the same error. I am using pgdev.305.jdbc3.jar for 8.0.0beta2. The PostgreSQL installation are standard,...
3
6321
by: Rodríguez Rodríguez, Pere | last post by:
Hello, I think I have found a query problem when the query has an alias for a table and use alias item and table name. I ilustrate the problem with a simple table and query. prr=# create table foo (c1 int2, c2 int2); CREATE TABLE prr=# insert into foo values (1, 1);
0
1297
by: Lee Blevins | last post by:
I'm trying to query a postgresql database with PHP. I am having a problem when using a WHERE. It works without the WHERE. Example: $query = "SELECT job_number, customer, desription, archive, date_opened, job_status FROM jobs WHERE job_status='In Progress' ";
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7965
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3838
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1184
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.