Обсуждение: ERROR: Can't Parse "" (PG and PHP on Linux)

Поиск
Список
Период
Сортировка

ERROR: Can't Parse "" (PG and PHP on Linux)

От
paulie808@yahoo.com (Paul)
Дата:
I've been spending way too much time in the last day trying to solve
this problem and hope someone can help me figure out what's wrong. I'm
running PostgreSQL and PHP with a Redhat Linux/Apache configuration,
and am having two major problems:

1.  The following PHP statement:

$strSQL = sprintf("INSERT INTO companies (comp_name, type_id) VALUES
('%s', %s);",$strCompName,trim($intTypeID));

yields the SQL statement:

INSERT INTO companies (comp_name, type_id) VALUES ('someName',9);

for example, which is legitimate, and when typed into the the shell
directly, the SQL statement does exactly what is expected. It also
does exactly what is expected if sent to PostgreSQL from PHP via a
pg_query() statement.

However, when I use the original statement, and assign $intTypeID to
the integer or string "9" (and the SQL is still output exactly the
same via a string) I get the following error from the server:

SQL: INSERT INTO companies (comp_name, type_id) VALUES ('Vendor', 10);
ERROR: parser: parse error at or near ")"

If I surround the second substitution with '', I get the following
error:

SQL: INSERT INTO companies (comp_name, type_id) VALUES ('test vendor',
'10');
ERROR: pg_atoi: error in "10": can't parse ""


While single quotes yields:

SQL: INSERT INTO companies (comp_name, type_id) VALUES ('test vendor',
"10");
ERROR: Attribute '10' not found


PLEASE HELP. This statement is perfectly legitimate. What is wrong
with my PostgreSQL??



2. When I try to drop old databases or tables, it gives an error
telling me that a user is using the database and can't drop the
table/database. I've even tried it after killing all processes on the
server and not being logged into the database I'm trying to drop
(i.e., logged into another database)

How can I solve this problem?

Thanks,
Paul

Re: ERROR: Can't Parse "" (PG and PHP on Linux)

От
Andrew Sullivan
Дата:
On Tue, Jul 30, 2002 at 07:05:05AM -0700, Paul wrote:
> 1.  The following PHP statement:
>
> $strSQL = sprintf("INSERT INTO companies (comp_name, type_id) VALUES
> ('%s', %s);",$strCompName,trim($intTypeID));
>
> yields the SQL statement:
>
> INSERT INTO companies (comp_name, type_id) VALUES ('someName',9);

Is that what your logs tell you it's yielding?  Given your errors, my
bet is that PHP is doing something you don't think it is.

> 2. When I try to drop old databases or tables, it gives an error
> telling me that a user is using the database and can't drop the
> table/database. I've even tried it after killing all processes on the
> server and not being logged into the database I'm trying to drop
> (i.e., logged into another database)

Are you sure there's no-one connected?  You've checked with ps?
Sounds like a connection isn't really dead.

A

--
----
Andrew Sullivan                               87 Mowat Avenue
Liberty RMS                           Toronto, Ontario Canada
<andrew@libertyrms.info>                              M6K 3E3
                                         +1 416 646 3304 x110


Re: ERROR: Can't Parse "" (PG and PHP on Linux)

От
Matthew Kirkwood
Дата:
On 30 Jul 2002, Paul wrote:

> $strSQL = sprintf("INSERT INTO companies (comp_name, type_id) VALUES
> ('%s', %s);",$strCompName,trim($intTypeID));

Lose the trailing semicolon.  The backend is probably
interpreting that as:

"insert foo" + empty statement

Matthew.