Jump to content

PostgreSQL + PHP, nao aceita maisculas?


Recommended Posts

$key = $_GET['key1'];

//SQL query to insert elements into table
echo "$key";
$sql_query = "DELETE FROM alimento WHERE designacao=$key";
$result = pg_query($dbconn, $sql_query);

no echo "$key" aparece Banana mas quando é feito o pg_query, é retornado o seguinte erro:

Warning: pg_query() [function.pg-query]: Query failed: ERROR: column "banana" does not exist in apagar_alimento.php on line 14

Cannot delete value from table alimento:ERROR: column "banana" does not exist

mas Banana existe, banana é que não, algum de idea de pq é que quando faço o query fica em minusculas?

Link to post
Share on other sites

k thx. usei addslahes() mas n resultou.

No entanto corrigi fazendo

$key = "'" . $_GET['key1'] . "'";

em vez de

$key = $_GET['key1'];

sendo que agr no echo temos 'Banana' com as '

e o postgreSQL ja le como sendo Banana e não banana, não sei se é a melhor maneira de fazer, mas resulta.

se alguem tiver alguma maneira melhor q diga sff.

Link to post
Share on other sites

$key = pg_escape_string($_GET['key1']);
$query = "DELETE FROM alimento WHERE designacao='$key'";

pg_escape_string() escapes a string for insertion into the database. It returns an escaped string in the PostgreSQL format. Use of this function is recommended instead of addslashes().

Em alternativa, o uso do PDO é sempre prático, nunca se sabe se não vais ter que mudar de BD no futuro.

❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents

A list  of command line apps

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.