Welcome Guest, Not a member yet? Register   Sign In
PostgreSQL where
#1

[eluser]Kfrico[/eluser]
Code:
$sql = "SELECT * FROM "AssocPersonMaster" WHERE "PersonID" = '9788771' or "Status" = 'b'";
$query = $this->db->query($sql);

Parse error: syntax error, unexpected T_STRING in E:\Program Files\Apache Software Foundation\www\pg\system\application\models\modelinsert.php on line 50

why

在sql裡面不能加雙引號嗎?
但是不加雙引號postgresql確無法判別大小寫之分
這該怎麼辦阿?
#2

[eluser]ray73864[/eluser]
I'm gonna tell you why, but it is pretty easy to see why so i think you should look over your code before asking questions. Anyway, the problem is with how you have done your query.

You are closing your double quotes before you name the table, so php is getting very confused and thinking that 'AssocPersonMaster is supposed to be something but it isn't sure what.

I think what you want would be this:

$sql = "SELECT * FROM AssocPersonMaster WHERE PersonID=? OR Status=?";
$query = $this->db->query($sql,array('9788771','b'));

I thin you should also read up on the 'Active Record' features of the database class, as it allows you to better drill down with your queries ie.

$this->db->select('*');
$this->db->from('AssocPersonManager');
$this->db->where('PersonID',9788771);
$this->db->or_where('Status','b');

$query = $this->db->get();

Also, never use * when doing a select query, mostly because it grabs every single column in your database which for 10 columns can slow you down a bit, it is better to name the columns you want to get out.
#3

[eluser]Kfrico[/eluser]
but PostgreSQL need "" Distinguish big small letter




if $sql = “SELECT * FROM AssocPersonMaster WHERE PersonID=? OR Status=?”;
$query = $this->db->query($sql,array(‘9788771’,‘b’));

Fatal error: Call to a member function result() on a non-object in
#4

[eluser]ray73864[/eluser]
If you want to do it the way you want to, then you will need to escape the double quotes, eg:

$sql = "SELECT * FROM \"AssocPersonMaster\" WHERE \"PersonID\" = '9788771' or \"Status\" = 'b'";
#5

[eluser]Kfrico[/eluser]
thanks
#6

[eluser]Kfrico[/eluser]
Excuse me,

$sql = "SELECT * FROM \"AssocPersonMaster\" WHERE \"PersonID\" = '$PersonID' OR \"Status\" = '$Status' ";


Why the variable $PersonID for NULL is an error?

but $Status for Null is OK
#7

[eluser]ray73864[/eluser]
I don't know your table structure, but assuming 'PersonID' is a primary key, it cannot be NULL
#8

[eluser]Kfrico[/eluser]
thanks




Theme © iAndrew 2016 - Forum software by © MyBB