in Education by
This question already has answers here: PHP parse/syntax errors; and how to solve them (21 answers) Closed 3 years ago. I have an application written in PHP, I'm connecting to a PGSQL database and selecting some data. This works as expected until I use the string concatenation operator (||) in the query. I connected tothe PGSQL db via PGadmin and generated the query, so I know it definitely works. I then copied the code and pasted it into my $query variable. My code is below; $dbconn = pg_connect("host=xxx dbname=xxx user=xxx password=xxx") or die('Could not connect: ' . pg_last_error()); $query = ' SELECT f.date_gmt::date as "Date Assessed" n.last_name || ', '' || n.first_name AS "Full Name" // line 12 FROM fines as f JOIN record_metadata as r ON r.id = f.record_metadata_id JOIN fullname as n ON n.id = f.record_metadata_id '; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); echo " \n"; while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) { echo "\t \n"; foreach ($line as $col_value) { echo "\t\t \n"; } echo "\t\n"; } echo "
$col_value
\n"; pg_free_result($result); pg_close($dbconn); The error produced is; Parse error: syntax error, unexpected ',' in /...index.php on line 12 Removing line 12 from the code resolves the issue. But, I need this data so what do I need to change in order to achieve what I want? Presumably I can't simply copy the working query from the PGSQL db and paste it into my PHP code? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You did not escape quote symbols '. You have 2 options. 1st escape them with back slashes: n.last_name || \', \'\' || n.first_name AS "Full Name" 2nd (suggested) Just use heredoc notation: $query = <<<QUERY SELECT f.date_gmt::date as "Date Assessed" n.last_name || ', '' || n.first_name AS "Full Name" FROM fines as f JOIN record_metadata as r ON r.id = f.record_metadata_id JOIN fullname as n ON n.id = f.record_metadata_id QUERY; Example here. || is concatenation operator for Postgres. I think you have typo there and this line n.last_name || ', '' || n.first_name AS "Full Name" has a typo, should be n.last_name || '', '' || n.first_name AS "Full Name"

Related questions

0 votes
    This question already has answers here: PHP parse/syntax errors; and how to solve them (21 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How can I convert ereg expressions to preg in PHP? (4 answers) ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This question already has an answer here: Quasar framework q-select sets an object in the v-model than ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I have an old project to work with, a lot of refactoring and so on. All the icons and images are ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I'm trying to use babel to run my NodeJS program, which includes ES6 syntax and exports from the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 13, 2022 in Education by JackTerrance
0 votes
    My XML looks like this- ValueGoesHere I am processing it using below code- Document dom = parser.getDocument ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    How do you handle a situation in which unexpected errors occur during the execution of a script?...
asked Oct 19, 2020 in Technology by JackTerrance
0 votes
    I tried installing Postgres with OpenSSL by doing ./configure --with-openssl but I got an error saying ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 14, 2022 in Education by JackTerrance
0 votes
    Installed Postgres-XC $>sudo apt-get install postgres-xc then $ postgres -V postgres (PostgreSQL) 9.2. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    Is there any reason to keep time series data in its own database, separate from other tables or is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    UPDATED Can't connect to a postgres database. The dependency of postgres is added via maven. Maven ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I know we are all using a bunch of ORMs for SQL, but I wanted to give a try to native drivers. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
...