★ wanayoo — archive 1999 http://www.php.net/manual/it/function.pg-exec.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to PostgreSQL
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageFrench version of this pageHungarian version of this page
PostgreSQL
* pg_Close
* pg_cmdTuples
* pg_Connect
* pg_DBname
* pg_ErrorMessage
* pg_Exec
* pg_Fetch_Array
* pg_Fetch_Object
* pg_Fetch_Row
* pg_FieldIsNull
* pg_FieldName
* pg_FieldNum
* pg_FieldPrtLen
* pg_FieldSize
* pg_FieldType
* pg_FreeResult
* pg_GetLastOid
* pg_Host
* pg_loclose
* pg_locreate
* pg_loexport
* pg_loimport
* pg_loopen
* pg_loread
* pg_loreadall
* pg_lounlink
* pg_lowrite
* pg_NumFields
* pg_NumRows
* pg_Options
* pg_pConnect
* pg_Port
* pg_Result
* pg_trace
* pg_tty
* pg_untrace
Manual: pg_Exec
View the source code for this pageSearch the site



Previous page
 pg_ErrorMessage
 Updated
Sun, 06 Aug 2000
pg_Fetch_Array 
Next page


pg_Exec

(unknown)

pg_Exec -- esegue una query

Descrizione

int pg_exec (int connection, string query)

Restituisce un indice di result se la query puņ venire eseguita, falso se fallisce o se connection non č un valido indice di connessione. Dettagli riguardo l'errore possono essere ottenuti usando la funzione pg_ErrorMessage() se connection č valido. Invia uno statement SQL al database PostgreSQL specificato dall'indice di connessione. Connection deve essere un indice valido restituito da pg_Connect(). Il valore restituito da questa funzione č un indice da usarsi per accedere ai result da altre funzioni PostgreSQL.

Nota: PHP/FI restituiva 1 se dalla query non ci si attendeva alcuna restituzione di dati (inserimenti o aggiornamenti, ad esempio) e valori maggiori di 1 anche su selezioni che non ritornavano alcunchč. Nessuna supposizione di questo genere puņ essere fatta in PHP.


User Contributed Notes: pg_Exec


jarrell@stiletto.com
13-Dec-1998 03:04
I can't seem to get my data to post. here is a sample of what my pg_exec line is.
pg_exec ($db_conn, "insert into clients clientid values clientid ");
do you have any insert examples for pg_exec



efm@tummy.com
15-Dec-1998 10:16
The correct form for a PostgreSQL insert
is

INSERT INTO clients (clientid), VALUES ('42');




bkosse@thecreek.com
19-May-1999 07:54
Make sure that you close any connections you have (or use persistant connections), otherwise your pg_exec() call may fail without any warnings showing up.


afader@asqnet.org
04-Sep-1999 05:23
(Boy this text window is small)
First, the note with the "... ), (..." is incorrect. The comma should be removed. The other problem is likely the data type you are sending. If you try to insert a '9' into a int4 you do get an error message.

<PRE>
$sqlq =
"INSERT INTO reviewers "
." ( name, email, webpage, passcode, ipaddress, alias, "
." phone, city, state, country, clearance ) "
." VALUES ('$name', '$email', '$webpage', '$passcode', "
." '$ipaddress', '$alias', '$phone', '$city', '$state', "
." '$country', $clearance );";
$e = pg_exec($db,$sqlq);
</PRE>



afader@asqnet.org
04-Sep-1999 05:25
doah - if you insert a '9' into an int4 you DONT get an error message - and the insert doesn't work. (Note '9' is a character, and 9 is a number.) Same goes for inserting text into numbers.


yuli@sprint.ca
07-Oct-1999 03:43
Can't figure out how to update;
i.e: there are two query sentences, so
what should I do? split them with semicolumn,
comma, or other??? I have no idea.
If any help will be appreciated, further detail please
email me.



griffi_r@epita.fr
27-Oct-1999 06:37
How do i know if a SELECT query returned no result ?


carlr@sempurna.com
28-Oct-1999 09:06
When doing a SELECT, I use the PG_NUMROWS() command to find out how many rows were where returned, if greater than 1 it was successful and then you can code to read the values.

Can anyone tell me how you know if an UPDATE was successful? Everything I have tried returns nothing of value for an unsuccessful update or successful update.



carlr@sempurna.com
29-Oct-1999 07:29
Sorry about the above but that should read equal-to or greater than (=>) one.
<PRE>
$result = ($database, "SELECT blah, blah...");
$rows = pg_numrows($result);
if ($rows => 1) {
echo "Found something....";
} else {
echo "Nothing there.";
}
</PRE>

But to find out if an UPDATE or INSERT worked is another question and one I wish I had an answer for.



chris@felidae.apana.org.au
31-Oct-1999 05:44
To see how many tuples (rows) are affected by UPDATE/INSERT/DELETE, use the pg_CmdTuples command.


mark@chalice.gen.nz
08-Dec-1999 11:17
If I do an 'insert into...' query, php doesn't seem to return a result set of the inserted data (which i've had other dbs do), I have a serial field and want to know what the new serial number is, how?


jason@familynet.net
10-Dec-1999 01:53
Insert returns an OID. Use the pg_GetLastOid() function to SELECT the last inserted row of your session. To get an automatic serialized id, set up your table like this:

<PRE>
SQL:

CREATE TABLE something (
"itemno" int4 PRIMARY KEY DEFAULT NEXTVAL('serial'),
"name" varchar(80),
);
CREATE SEQUENCE serial INCREMENT 1 START 1;


PHP Example:

$result=pg_exec($conn,"INSERT INTO customer (name) VALUES ('test');");
if(!$result) {
error("Unable to update.");
}
else {
// display
$oid = pg_GetLastOid($result);
if($oid<0) error("bad news");
$result=pg_exec($conn,"SELECT itemno FROM customer WHERE oid = $oid;");
if(!$result) error("worse news");
$arr = pg_fetch_array ($result, 0);
echo "

ItemNo: $arr[0]

";
}
</PRE>



none
12-Dec-1999 06:02
how do you convert this command to a mysql command?


kajla@kredit.sth.szif.hu
15-Dec-1999 09:42
hi all, can anyone explain this?

I have a db:
blaskovics=> select * from volvo_ar where modell='S70';
modell|utotag |urtart| kw| le| ar
------+---------+------+---+---+-------
S70 |2.4 140HP| 2435|103|140|8631000
S70 |2.4 170HP| 2435|125|170|8989000
S70 |2.5 D | 2461|103|140|9359000
(3 rows)

and I have a code:
$mod='S70'; $volvo_ar = pg_Exec ($conn, "SELECT * FROM volvo_ar WHERE modell = $mod ");

and this code results:

Warning: PostgresSQL query failed: ERROR: attribute 's70' not found in /home/httpd/html/blaskovics/var1.php3 on line 66

Does someone know why changes the content of $mod into lower-case?




lithis@cpinternet.com
15-Jan-2000 01:25
postgres appears to convert all identifiers to lowercase. however, this isn't your problem. you need to put single quotes around $mod in the where condition. it's trying to find a field named s70, not a field containing 's70'.


bradleytsi@aol.com
19-Jan-2000 12:02
I hope this helps, I don't quite understand your question though. If
this doesn't help, e-mail me back with a revised question.
<pre>$sql = "UPDATE intranuser SET user_id = '$user_id', pword='$pword',
e_mail='$e_mail', question='$question', answer='$answer' WHERE surname =
'$surname' AND first_name = '$first_name';";</pre>

Also, here is a web site that should help you out:
http://w3.one.net/~jhoffman/sqltut.htm



knight@novell.ohsh.u-szeged.hu
21-Jan-2000 05:05
I suppose pg_GetLastOid() returns a zero value when you want to insert a duplicate key. So checking should be the following:
<pre>if (!pg_GetLastOid($result) ||
(pg_GetLastOid($result) < 0)) {
code_on_error
else {
code_on_success
}
</pre>



floino@hotmail.com
06-Feb-2000 11:32
If you use addslashes command, when you insert a field in database the data will contain the backslashes too


jason@familiynet.net
11-Jul-2000 10:47
To retrieve the data you just saved and to get an automatic serialized id, set up your table like this:
<PRE>
SQL:

CREATE TABLE something (
"itemno" int4 PRIMARY KEY DEFAULT NEXTVAL('serial'),
"name" varchar(80), );

CREATE SEQUENCE serial INCREMENT 1 START 1;

-----------------

PHP Example:

$result=pg_exec($conn,"INSERT INTO customer (name) VALUES ('test');");

// find out what itemno the database assigned
$oid = pg_GetLastOid($result);
$result=pg_exec($conn,"SELECT itemno FROM cookie WHERE oid = $oid;");
$arr = pg_fetch_array ($result, 0);
$itemno = $arr[0];

</PRE>



jeff@pgsql.com
13-Aug-2000 10:11
few note/tips for everyone out there

1: that getlast oid or whatever it's called. that's slow and painful.. try this.

if your table (ie "users" has a serial type (ie "uid") and you want to find out the most recent one. do this select
SELECT currval('id_users_seq');

2nd tip to see if a INSERT/UPDATE worked
or not and how to suppress it's error message

1: $insert=@pg_exec($dbh,$insertstring)
if ($insert == 0 ) { /* it screwed up */ }

2: the @ infron of pg_exec suppresses the errors.

jeff@pgsql.com



 About Notes


Previous page
 pg_ErrorMessage
 Updated
Sun, 06 Aug 2000
pg_Fetch_Array 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.