Received: from mail.SC-Networks.de ([194.221.237.226]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f05APf790017 for ; Fri, 5 Jan 2001 05:25:41 -0500 (EST) (envelope-from irrgang@sc-networks.de) Received: from heiko.sc-networks.de ([192.168.66.11]) by mail.SC-Networks.de with esmtp (Exim 3.16 #6) id 14EV28-0006HC-00 for pgsql-general@postgresql.org; Fri, 05 Jan 2001 12:27:44 +0100 Mime-Version: 1.0 X-Sender: irrgang@mail.sc-networks.de Message-Id: In-Reply-To: <0101050121130A.01054@jdavis> References: <0101050121130A.01054@jdavis> Date: Fri, 5 Jan 2001 11:25:12 +0200 To: pgsql-general@postgresql.org From: Heiko Irrgang Subject: Re: Explain Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Archive-Number: 200101/172 X-Sequence-Number: 2338 >How can I conveniently handle output from an EXPLAIN query inside an >application? It appears to just immediately send the output to the stdout of >whatever program uses it. Is there a way to get the output inside a program, >with libpq or otherwise? I would actually like to be able to get the output in >a PHP script, but getting it in any application would be nice. AFAIK it dont works directly, but you can do the following: /dev/stdout","r"); while($nextline=fgets($f,4096)) { echo($nextline."
"); } pclose($f); ?> this would dump the explain-result as you get it in psql as html-text. with popen("command","r") you open a stream to the command and because psql seems to send the result of explain to stderr you have to redirect it to stdout (2>/dev/stdout) then you can handle the filedescriptor delivered by popen() as a normal file with fgets(), but you have to close it with pclose() not fclose(). this works exactly the same within a c program but i dont know much about programming postgres in c. it may be possible to have the same result directly with libpq, but for php this seems to be the only way to do this. -- SC-Networks www: www.SC-Networks.de Web Design, Netzwerke, 3D Animation und Multimedia Heiko Irrgang Tel.: 08856/9392-00 Im Thal 2 Fax: 08856/9392-01 82377 Penzberg Mail: Irrgang@SC-Networks.de