2
$result = pg_query(Postgres::getInstance(), "SELECT 
date_start, 
date_end, 
cnt_hands, 
cnt_hands_won, 
amt_won, 
id_session,
id_player,
amt_won  
FROM 
cash_table_session_summary 
WHERE 
date_start = '2016-04-27 07:20:47'");

This works perfectly.

echo $sessionStart;
$result = pg_query(Postgres::getInstance(), "SELECT 
date_start, 
date_end, 
cnt_hands, 
cnt_hands_won, 
amt_won, 
id_session,
id_player,
amt_won  
FROM 
cash_table_session_summary 
WHERE 
date_start = $sessionStart");

This throws this:

2016-04-27 07:20:47 Warning: pg_query(): Query failed: ERROR: syntax error at or near "07" LINE 13: ... date_start = 2016-04-27 07:20:47 ^ in /home/haris/public_html/project/DAL_General.php on line 102

Is colon a problem? Do I need to escape it somehow? If so, how? I've google but found nothing about escaping colons.

2
  • 2
    Use it as date_start = '$sessionStart'" inside single quotes Commented Apr 30, 2016 at 10:04
  • 1
    Thanks! I'm new to php, and it didn't even occured to me, that that is possible. Can you make an answer, so I can mark it as correct? Commented Apr 30, 2016 at 10:08

2 Answers 2

1

Your date must be inside quotes. You need to change

FROM 
cash_table_session_summary 
WHERE 
date_start = $sessionStart

To

FROM 
cash_table_session_summary 
WHERE 
date_start = '$sessionStart'// add quotes here

For more understand about quotes check When to use single quotes, double quotes, and backticks in MySQL

Sign up to request clarification or add additional context in comments.

Comments

1

I had the same issue when I was learning database work, but you need the query to be made in ""'s - Then when referencing a variable or data you need to put it in ''s, example:

$test_query = type_of_connection_query("SELECT * FROM users WHERE id = '1'");

That would not work like:

$text_query = type_of_connection_query("SELECT * FROM users WHERE id = 1");

And of course there are some times when you don't need quotes, like referencing LIMIT's

$text_query = type_of_connection_query("SELECT * FROM users WHERE id = '1' LIMIT 1");

Comments

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.