0

When a column alias was used like below to get data from PostgreSQL, the PHP code doesn't run. However, when I don't use column alias, then the PHP code works so I know that my PHP code is correct. Is there a way to make column alias works from PostgreSQL and within PHP framework?

$SQL1 = "
SELECT count(distinct emcas_gbo_gs.w_customer_d.cust_id) as "CNT"
FROM emcas_gbo_gs.w_customer_d 
";

$dataQuery1 = pg_query($mycon, $SQL1) or die('Query failed: ' . pg_last_error());
$dataCnt1   = pg_fetch_result($dataQuery1,0,'CNT');

1 Answer 1

1

If you look at the code in your question and the way Stackoverflow formatted it you can see that CNT is not inside the string.

You should simply remove the doublequotes around CNT:

$SQL1 = "
SELECT count(distinct emcas_gbo_gs.w_customer_d.cust_id) as CNT
FROM emcas_gbo_gs.w_customer_d 
";
1
  • Double quotes were removed and the PHP code works. Thank you for the solution! Commented Dec 5, 2013 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.