OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 8 Jan 2007 03:37:52 -0000 Issue 4557

php-general-digest-helplists.php.net
Date: Sun Jan 07 2007 - 21:37:52 CST


php-general Digest 8 Jan 2007 03:37:52 -0000 Issue 4557

Topics (messages 246702 through 246731):

Re: Exceptions: How much is too much.
        246702 by: Craige Leeder
        246711 by: Roman Neuhauser

Re: Question regarding include() and symlinks to directories
        246703 by: spam.pflaesterer.de> (Karl Pflästerer)
        246704 by: spam.pflaesterer.de> (Karl Pflästerer)
        246705 by: Robert Cummings

PHP Manipulation of WMV
        246706 by: Casey Chu
        246707 by: Jochem Maas
        246709 by: Casey Chu
        246710 by: Jochem Maas

OT - web based project management tool
        246708 by: Peter Lauri
        246712 by: Roman Neuhauser
        246713 by: Jochem Maas
        246715 by: Skip Evans
        246717 by: Jochem Maas

Re: Search script problem
        246714 by: Jochem Maas
        246716 by: Jochem Maas
        246723 by: Jochem Maas

Re: Windows directory listings
        246718 by: Beauford
        246724 by: Jochem Maas
        246728 by: Beauford

XML API, libcurl, POST Help Needed
        246719 by: Richard Luckhurst
        246722 by: Jochem Maas
        246729 by: Richard Luckhurst

Syntax Error
        246720 by: JD
        246721 by: Chris
        246727 by: Chris

ODBC and long text fields
        246725 by: Larry Garfield
        246726 by: Jochem Maas
        246730 by: Larry Garfield

Re: How to suppress error messages when using 'new mysqli(...)'
        246731 by: Ligaya A. Turmelle

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

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

attached mail follows:


Thanks.

Does anybody else have any input? Not to be pushy, but I'm in the
middle of programming a framework for a site.

- Craige

On 1/5/07, Paul Scott <pscottuwc.ac.za> wrote:
>
> On Fri, 2007-01-05 at 00:44 -0500, Craige Leeder wrote:
> > The question is: How much is too much. Should I use Exceptions to
> > handle all of my error reporting/triggering? How about catching them?
> > I mean, if I'm using Exceptions for all of my error handling, I could
> > easily end up wrapping my entire script in a try block(or at least
> > having almost all my end-code within a number of them).
>
> Not sure if I am doing it correctly either, but, what I do is use
> try/catch blocks to instantiate all of the objects that I need and then
> let the script take over. I also use exceptions to handle SQL errors in
> my db abstraction object(s). That way, only real messes are caught and
> the script then displays a graceful exit page to the user instead of
> screen vomit that may scare them off.
>
> --Paul
>
>
>
> All Email originating from UWC is covered by disclaimer http://www.uwc.ac.za/portal/uwc2006/content/mail_disclaimer/index.htm
>
>
>

attached mail follows:


# cleedergmail.com / 2007-01-07 13:17:23 -0500:
> On 1/5/07, Paul Scott <pscottuwc.ac.za> wrote:
> >On Fri, 2007-01-05 at 00:44 -0500, Craige Leeder wrote:
> >> The question is: How much is too much. Should I use Exceptions to
> >> handle all of my error reporting/triggering? How about catching them?
> >> I mean, if I'm using Exceptions for all of my error handling, I could
> >> easily end up wrapping my entire script in a try block(or at least
> >> having almost all my end-code within a number of them).
> >
> >Not sure if I am doing it correctly either, but, what I do is use
> >try/catch blocks to instantiate all of the objects that I need and then
> >let the script take over. I also use exceptions to handle SQL errors in
> >my db abstraction object(s). That way, only real messes are caught and
> >the script then displays a graceful exit page to the user instead of
> >screen vomit that may scare them off.
>
> Does anybody else have any input? Not to be pushy, but I'm in the
> middle of programming a framework for a site.

I didn't see a real question in your original email. Otherwise, the
answer is 42.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

attached mail follows:


On 6 Jan 2007, ceol-i-e.com wrote:

> On Thu, January 4, 2007 2:47 pm, Karl Pfl=E4sterer wrote:
>> In my opinion include() should respect symlinks to directories and not
>> dereference them before finding the file to include. Or am I wrong
>> here?
>> The PHP version is 5.1.6 (will soon be updated).
>
> WHOOPS!
>
> My fingers slipped and I keyboarded to "Send" button.
>
> SORRY!
>
> ... and use full pathname when you go to read a file.
>
> Anything else is more like playing an Adventure Game than Programming.

IMO you're absolutely right, but I didn't ask the question out of sheer
curiosity but it has to do with the way script files (here at work) find
the right files to include for navigation, banners etc. Symlinks to
files and directories are used a lot and sometimes it's very convenient
to include some files with an absolute path (the files which are the
same for all) and some files with a relative path (the files specific
for one page). mod_include had been used before PHP and it was common
to use this technique.

   KP

attached mail follows:


On 5 Jan 2007, robertinterjinn.com wrote:

>
> On Fri, 2007-01-05 at 22:07 +0100, Jochem Maas wrote:
>> reply at the bottom ...
>>
>> (Karl Pflästerer) wrote:
>> > Hi
>> > let's say we have the follwing directory structure:
>> > directory test, with to subdirectories: a and b; both have ssi
>> > subdirectory; a has also a subdirectory c with an index.php file in it
>> > and in b we habe a symbolic link to a/c.
>> >
>> > On the shell it looks like this:
>> > ,----
>> > | /htdocs/test>ls -gG *
>> > | a:
>> > | total 8
>> > | drwxr-xr-x 2 4096 Jan 4 20:55 c
>> > | drwxr-xr-x 2 4096 Jan 4 20:51 ssi
>> > |
>> > | b:
>> > | total 4
>> > | lrwxrwxrwx 1 6 Jan 4 20:53 c -> ../a/c
>> > | drwxr-xr-x 2 4096 Jan 4 20:53 ssi
>> > | ~/htdocs/test>cat a/ssi/a.inc
>> > | In directory a
>> > |
>> > | ~/htdocs/test>cat b/ssi/a.inc
>> > | In directory b
>> > `----
>> >
>> > As you see whe have an a.inc in each ssi. If we call now the index.php
>> > which does nothing more than to:
>> > include('../ssi/a.inc')
>> > what would you expect to read if you called b/c/index.php? I expected to
>> > read 'In directory b' but I read 'In directory a'.
>> >
>> > ,----
>> > | ~/htdocs/test>(cd a/c && php -f index.php )
>> > | In directory a
>> > |
>> > |
>> > | ~/htdocs/test>(cd b/c && php -f index.php )
>> > | In directory a
>> > `----
>> >
>> > In my opinion include() should respect symlinks to directories and not
>> > dereference them before finding the file to include. Or am I wrong here?
>>
>> I have tested using your exact description and get the result, you can
>> be fairly certain this is not something specific to your server/machine.
>>
>> I would tend to agree with your premise - but the php devs may have
>> decided against this behaviour on purpose.
>
> PHP needs to dereference symlinks so it knows exactly where it is in
> case of security violations. This prevents symlinking into paths for
> which you don't have access... especially important on shared hosts.

I always thought this kind of check would only be done if you used
safe_mode. If you're not a shared host there's no need for this kind of
check. Everyone who has the ability to place a php script on the server
also has shell access (here at work at least). To explain why I asked
about this behaviour (so it's not only a convoluted example I showed but
a simplified version of an existing directory structure (if it would be
done that way today is another question)) see also MID
<u3b6mbshf.fsfhamster.pflaesterer.de>.

>
> Cheers,
> Rob.
> --
> .------------------------------------------------------------.
>| InterJinn Application Framework - http://www.interjinn.com |
> :------------------------------------------------------------:
>| An application and templating framework for PHP. Boasting |
>| a powerful, scalable system for accessing system services |
>| such as forms, properties, sessions, and caches. InterJinn |
>| also provides an extremely flexible architecture for |
>| creating re-usable components quickly and easily. |
> `------------------------------------------------------------'

   KP

attached mail follows:


On Sun, 2007-01-07 at 19:39 +0100, spampflaesterer.de wrote:
> On 5 Jan 2007, robertinterjinn.com wrote:
>
> >
> > On Fri, 2007-01-05 at 22:07 +0100, Jochem Maas wrote:
> >> reply at the bottom ...
> >>
> >> (Karl Pflästerer) wrote:
> >> > Hi
> >> > let's say we have the follwing directory structure:
> >> > directory test, with to subdirectories: a and b; both have ssi
> >> > subdirectory; a has also a subdirectory c with an index.php file in it
> >> > and in b we habe a symbolic link to a/c.
> >> >
> >> > On the shell it looks like this:
> >> > ,----
> >> > | /htdocs/test>ls -gG *
> >> > | a:
> >> > | total 8
> >> > | drwxr-xr-x 2 4096 Jan 4 20:55 c
> >> > | drwxr-xr-x 2 4096 Jan 4 20:51 ssi
> >> > |
> >> > | b:
> >> > | total 4
> >> > | lrwxrwxrwx 1 6 Jan 4 20:53 c -> ../a/c
> >> > | drwxr-xr-x 2 4096 Jan 4 20:53 ssi
> >> > | ~/htdocs/test>cat a/ssi/a.inc
> >> > | In directory a
> >> > |
> >> > | ~/htdocs/test>cat b/ssi/a.inc
> >> > | In directory b
> >> > `----
> >> >
> >> > As you see whe have an a.inc in each ssi. If we call now the index.php
> >> > which does nothing more than to:
> >> > include('../ssi/a.inc')
> >> > what would you expect to read if you called b/c/index.php? I expected to
> >> > read 'In directory b' but I read 'In directory a'.
> >> >
> >> > ,----
> >> > | ~/htdocs/test>(cd a/c && php -f index.php )
> >> > | In directory a
> >> > |
> >> > |
> >> > | ~/htdocs/test>(cd b/c && php -f index.php )
> >> > | In directory a
> >> > `----
> >> >
> >> > In my opinion include() should respect symlinks to directories and not
> >> > dereference them before finding the file to include. Or am I wrong here?
> >>
> >> I have tested using your exact description and get the result, you can
> >> be fairly certain this is not something specific to your server/machine.
> >>
> >> I would tend to agree with your premise - but the php devs may have
> >> decided against this behaviour on purpose.
> >
> > PHP needs to dereference symlinks so it knows exactly where it is in
> > case of security violations. This prevents symlinking into paths for
> > which you don't have access... especially important on shared hosts.
>
> I always thought this kind of check would only be done if you used
> safe_mode. If you're not a shared host there's no need for this kind of
> check. Everyone who has the ability to place a php script on the server
> also has shell access (here at work at least). To explain why I asked
> about this behaviour (so it's not only a convoluted example I showed but
> a simplified version of an existing directory structure (if it would be
> done that way today is another question)) see also MID
> <u3b6mbshf.fsfhamster.pflaesterer.de>.

I don't know for sure, I made some assumptions as a case example of why
the dereferencing might occur. Either way though, if you have one
behaviour in one situation, for portability, you had best have the same
behaviour in every situation :) Another question might be... does apache
dereference? If so, maybe PHP is just following suit :)

Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'

attached mail follows:


Hello. Is there a way to manipulate WMV files with PHP? I need to do
so with an include().

attached mail follows:


Casey Chu wrote:
> Hello. Is there a way to manipulate WMV files with PHP? I need to do
> so with an include().

the mind boggles as to what the correlation is between needing to
manipulate a file and having to use include.

with regard to file manipulation - a file is a file is a file, if
you can read from it and write to it then you can manipulate... undoubtedly
that's not very helpful.

try explaining what it is that you want to do with the WMV, there may be
a way to do it.

>

attached mail follows:


Okay, sorry if I wasn't clear. I need to get frames from a WMV
dynamically with PHP. If the way to do is not a native PHP function, I
need to use an include() to get the functions because I can't use
extensions.

On 1/7/07, Jochem Maas <jochemiamjochem.com> wrote:
> Casey Chu wrote:
> > Hello. Is there a way to manipulate WMV files with PHP? I need to do
> > so with an include().
>
> the mind boggles as to what the correlation is between needing to
> manipulate a file and having to use include.
>
> with regard to file manipulation - a file is a file is a file, if
> you can read from it and write to it then you can manipulate... undoubtedly
> that's not very helpful.
>
> try explaining what it is that you want to do with the WMV, there may be
> a way to do it.
>
>
>
> >
>
>

attached mail follows:


Casey Chu wrote:
> Okay, sorry if I wasn't clear. I need to get frames from a WMV
> dynamically with PHP. If the way to do is not a native PHP function, I
> need to use an include() to get the functions because I can't use
> extensions.

extracting frames from a video file/stream is not quite at the same level
of complexity as say extract a substring from a string - if you get my point.

you will need to have the ffmpeg program available on your system, get your
sys admin to install if it's not there.

doing a quick search I found the following class which acts as a wrapper to
the ffmpeg command line program (and as the blurb mentions doesn't require
recompiling php or loading extensions):

https://trac.phpgraphy.org/trac/browser/phpgraphy/trunk/base/include/yorsh-ffmpeg-wrapper.class.php?rev=367

there are probably other similar bits of code out and about if you do
a thorough search.

no doubt there are alternative programs that do what ffmpeg does but ffmepg
is the only [free] one I could think of right now.

>
> On 1/7/07, Jochem Maas <jochemiamjochem.com> wrote:
>> Casey Chu wrote:
>> > Hello. Is there a way to manipulate WMV files with PHP? I need to do
>> > so with an include().
>>
>> the mind boggles as to what the correlation is between needing to
>> manipulate a file and having to use include.
>>
>> with regard to file manipulation - a file is a file is a file, if
>> you can read from it and write to it then you can manipulate...
>> undoubtedly
>> that's not very helpful.
>>
>> try explaining what it is that you want to do with the WMV, there may be
>> a way to do it.
>>
>>
>>
>> >
>>
>>

attached mail follows:


Hi,

 

What project management tool do you use for your project? Is dotProject
(www.dotproject.org <http://www.dotproject.org/> ) only alternative?

 

Best regards,

Peter Lauri

 

 <http://www.dwsasia.com/> www.dwsasia.com - company web site

 <http://www.lauri.se/> www.lauri.se - personal web site

 <http://www.carbonfree.org.uk/> www.carbonfree.org.uk - become Carbon Free

 

attached mail follows:


# listsdwsasia.com / 2007-01-07 21:34:48 +0200:
> What project management tool do you use for your project? Is dotProject
> (www.dotproject.org <http://www.dotproject.org/> ) only alternative?

trac is popular.

--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man. You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

attached mail follows:


Peter Lauri wrote:
> Hi,
>
>
>
> What project management tool do you use for your project? Is dotProject
> (www.dotproject.org <http://www.dotproject.org/> ) only alternative?

I don't understand the second part of your question and I don't see that
dotproject.org is even a tool for project management.
(It might be my temporary blindness that's to blame :-)

2 project management tools I've used are:

sourceforge http://www.vasoftware.com/sourceforge/
trac http://trac.edgewall.org/

and for code control - CVS or SVN, both the above [can] integrate CVS and SVN.

attached mail follows:


I use dotProject, and what I like most about it is
it is quite easy to modify and enhance. For
example, it uses a PDF library (name escapes me at
the moment) and in 2 hours I wrote a quite nice
invoicing module for it.

I know, I think there is already one out there,
but I like to add my own features and stuff, and
was also very curious to see just how easy dP was
to modify/enhance, and I found it quite easy.

Just my two bits.

Skip

Jochem Maas wrote:
> Peter Lauri wrote:
>
>>Hi,
>>
>>
>>
>>What project management tool do you use for your project? Is dotProject
>>(www.dotproject.org <http://www.dotproject.org/> ) only alternative?
>
>
> I don't understand the second part of your question and I don't see that
> dotproject.org is even a tool for project management.
> (It might be my temporary blindness that's to blame :-)
>
> 2 project management tools I've used are:
>
> sourceforge http://www.vasoftware.com/sourceforge/
> trac http://trac.edgewall.org/
>
> and for code control - CVS or SVN, both the above [can] integrate CVS and SVN.
>

--
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240

attached mail follows:


Skip Evans wrote:
> I use dotProject, and what I like most about it is it is quite easy to
> modify and enhance. For example, it uses a PDF library (name escapes me
> at the moment) and in 2 hours I wrote a quite nice invoicing module for it.
>
> I know, I think there is already one out there, but I like to add my own
> features and stuff, and was also very curious to see just how easy dP
> was to modify/enhance, and I found it quite easy.

ah, so dotproject is a project management tool ...
it's just that the site is at dotproject.net and not
dotproject.org

>
> Just my two bits.
>
> Skip
>
> Jochem Maas wrote:
>> Peter Lauri wrote:
>>
>>> Hi,
>>>
>>>
>>>
>>> What project management tool do you use for your project? Is dotProject
>>> (www.dotproject.org <http://www.dotproject.org/> ) only alternative?
>>
>>
>> I don't understand the second part of your question and I don't see that
>> dotproject.org is even a tool for project management.
>> (It might be my temporary blindness that's to blame :-)
>>
>> 2 project management tools I've used are:
>>
>> sourceforge http://www.vasoftware.com/sourceforge/
>> trac http://trac.edgewall.org/
>>
>> and for code control - CVS or SVN, both the above [can] integrate CVS
>> and SVN.
>>
>

attached mail follows:


Wikus Moller wrote:
> Hi.
>
> I am having problems with a script I wrote which searches keywords
> from a field in a mysql db table.
>
> It is a very simple, one-page script. My site is a toplist, very
> basic, still in it's infancy. When I go to the page, key in the
> keywords and press submit, the head, body etc. part of the result
> script is shown, but no results.
> , although there are rows in my database containing the `keyword` field
> data.
>
> Below is the script, please see if you find any errors, it could be
> that I just made a stupid mistake.

imho your first stupid mistake was writing a script that bloody
unmanagable.

1. check you input
2. do some processing
3. ouput your page (including any error msgs from step 1 and 2)

this is in contrast to the tactic your using, namely: dump some output,
do something, dump more output, perform a query, dump some output, do
stuff, dump some output in a loop, do stuff, dump some output, etc.

PPPPP.

read on ...

>
> <?php
>
> echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
> echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML Mobile 1.0//EN\"
> \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">";
> echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
>
> error_reporting(E_ALL ^ E_NOTICE);
>
> $pwd = $_GET["pwd"];
> $uid = $_GET["uid"];
> $action = $_GET["action"];
> $cid = $_GET["cid"];
> $sid = $_GET["sid"];
> $var = $_GET["q"];

echo 'is this your expected input? : <pre>';
var_dump($_GET)
echo '</pre>';

>
> include ("function.php");
> include ("config.php");
> connect($dbserver,$dbname,$dbuser,$dbpass);
>
>
>
> /////////////////////////////////////////////Search main page
> if(!isset($var)){
> echo "<head>";
> echo "<title>Search Engine</title>";
> echo "<style type=\"text/css\">
> .m3 {background-color: #291C6F;}
> .n1 {background-color: #A0A0A0;}
> .n2 {background-color: #888888;}
> .c2 {color: #000000;}
> .m2 {color: #91D0FF;}
> body {font-family: Arial, sans-serif;
> font-size: 12px;
> color: #ffffff;
> background-color: #000033;
> margin-left: 0px;
> margin-right: 0px;
> margin-top: 0px;}
> .ct1 {font-family: Arial, sans-serif;
> font-size: 12px;
> color: #800080;}
> .cre {background-color: #1300A4;
> padding: 2px 2px 2px 2px;
> margin: 3px 0 0;
> font-size: 12px;
> color:#000000;
> text-align: center;
> border-width:1px 0;
> border-style:solid;
> border-color:#000000;}

use a css file and save a bit of band width (and scrolling in my case).

> </style>";
> echo "</head>";
> echo "<body>";
> echo "<table>";
> echo "<div class=\"cre\">";
> echo "<b>Search Engine</b></div>";
> echo "<form method=\"GET\"
> action=\"search.php?uid=$uid&amp;pwd=$pwd\">"; ///the uid and pwd is
> nessecary cause my member features are very basic and the urls is used
> to keep the user 'logged in'

basic is the wrong word if your are thinking in terms of security -
non-existent is closer to the truth. http://phpsec.org is a good place to
and learn about security on all [php] fronts

> echo "Keywords: <input type=\"text\" name=\"q\" /><br/>";
> echo "<input type=\"submit\" name=\"Submit\"/>";
> echo "</form>";
> echo "</table>";
> echo "<div class=\"cre\"><img src=\"images/home.gif\" alt=\"*\"/><a
> href=\"index.php?uid=$uid&amp;pwd=$pwd\">Home</a></div>";
> echo "</body>";
> echo "</html>";
> }
>
> ///////////////////////////////////////////////////Display Results
>
> if(isset($var)){

the following line is pointless given the line about and the
fact that you have already set $var in exactly the same way at the
top of your script.

> $var = $_GET["q"];
> $trimmed = trim($var); //trim whitespace from the stored variable
> echo "<head>";
> echo "<title>Search Results</title>";
> echo "<style type=\"text/css\">
> .m3 {background-color: #291C6F;}
> .n1 {background-color: #A0A0A0;}
> .n2 {background-color: #888888;}
> .c2 {color: #000000;}
> .m2 {color: #91D0FF;}
> body {font-family: Arial, sans-serif;
> font-size: 12px;
> color: #ffffff;
> background-color: #000033;
> margin-left: 0px;
> margin-right: 0px;
> margin-top: 0px;}
> .ct1 {font-family: Arial, sans-serif;
> font-size: 12px;
> color: #800080;}
> .cre {background-color: #1300A4;
> padding: 2px 2px 2px 2px;
> margin: 3px 0 0;
> font-size: 12px;
> color:#000000;
> text-align: center;
> border-width:1px 0;
> border-style:solid;
> border-color:#000000;}
> </style>";
> echo "</head>";
> echo "<body>";
> echo "<div class=\"cre\">";
> echo "<b>Search Results</b></div>";
> echo "<table>";
> // Get the search variable from URL
>
>
>
> // check for an empty string and display a message.
> if ($trimmed == "")
> {
> echo "Please enter a search...";
> exit;
> }
>
>
>
> if($pg==0)$pg=1;
> $pg--;
> $lmt = $pg*20;
> $pg++;
> $cou =$lmt+1;

is your table called 'table'? that is the WORST name in the world for
a table - and it will break your queries unless you stick them in backticks, e.g.:

        $res = mysql_query("SELECT COUNT(*) FROM `table`");

> $scount = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM table

you are not checking the return value of mysql_query().
you need to learn to do error checking at every stage of your script ...
it's a pain at first but eventually it *should* become second nature.

at the very very least do something like this:

        $res = mysql_query("SELECT COUNT(*) FROM `table`") or die('query failure');

personally I consider this moronic error checking but it's better than nothing.

> WHERE keywords like \"%$trimmed%\" AND banned='0' AND hitsin >=
> '2'"));
> $pgs = ceil($scount[0]/20);
> // Build SQL Query
> $sql = "SELECT * FROM table WHERE keywords like \"%$trimmed%\" AND
> banned='0' and hits_in >='2' ORDER by hin DESC LIMIT ".$lmt.", 20;";

dump out $sql (and the 'count' query above it) and check they are what you think
they are, then run them through phpmyadmin (directly in the mysql command line
tool) to check they do what you think they do.

attached mail follows:


please keep it on the list.

Wikus Moller wrote:
> Let me repeat myself, SIMPLE, this was just the starting point.

niether 'simple' or 'starting point' equate to 'ugly' or 'shit'
though do they. even simple scripts deserve error checking and
a managable layout.

I wasn't pointing that out to make you feel bad but to give you a
leg up in better script writing ...

>
> The error was caused due to a field being created after there were
> already rows in the table.

that *shouldn't* cause you any errors. the most likely reason it
did is your scripts assumption of the physical field order of your table.

I would recommend not using mysql_fetch_array() instead switch to
mysql_fetch_assoc() and reference the elements in the returned array
by name rather than by number - this has 2 advantages:

1. you won't get bitten by fields that were added to the table after
the script was written.
2. the output you generate using the returned array is alot more understandable:

        e.g. $row['name'] as compared to $row[0]

>
> It works like a dream and now I will correct the errors you pointed
> out and which you assumed I didn't know and which had no relevance to
> my query after I stated so boldly that it was simple.

a. I merely assumed that you *may* not be aware of the things I pointed
out, if you are aware of those points then there was really no harm done,
if you weren't then you would have been armed some new info ...

b. you can't control the answer, only the question, stop trying :-)

>
> Thanks

...

attached mail follows:


top posting.

what sucks?

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

still having trouble keeping your posts on lists?
if you want to put me in my place, that's fine but please
keep it on list where it belongs - if only because private flames
wars are so boring.

Wikus Moller wrote:
> Oops, I gave you the wrong link, here is the correct one where you can
> gain some knowledge:
>
> http://google.com/search?q=How+to+answer+questions+without+trying+to+look+smart
>

firstly, I can't actually see anything very specific to the query in the results.
secondly the first item in the results is primarily aimed at *you* (given that
you asked the question).

with regard to this page: http://catb.org/~esr/faqs/smart-questions.html
I am aware of it, I've read it a number of times, it's been posted on this
list numerous times and at least 1 long time list member actually carries the
link in his signature.

with regard to the last section on that page entitled
'How To Answer Questions in a Helpful Way' I don't feel I
transgressed any on of the points made, other than possibly 'be gentle' -
obviously you didn't consider it a gentle reply but it was comparitively gentle
by my usual standards.

with regard to looking smart - I don't kind looking smart at all, I consider myself
smart & *reasonably* knowledge with regard to using php - not perfect, not gifted, not
exceptional in anyway, but smart nonetheless. if that makes you feel inferior
you have one simple recourse - become, in your mind, smarter than me :-) I'll welcome
it, it would mean one more mind on this list capable of solving problems and
help raise the level of php hacking in general.

>
>
> On 1/8/07, Wikus Moller <wikus.mgmail.com> wrote:
>> Thats fine with me ^.^
>>
>> Here are some tips for you when you answer a question next time:
>>
>> http://google.com/search?p=How+to+answer+a+question+without+trying+to+look+smart
>>
>>
>> Thanks
>> Wikus
>>
>>
>> On 1/7/07, Jochem Maas <jochemiamjochem.com> wrote:
>> > please keep it on the list.
>> >
>> > Wikus Moller wrote:
>> > > Let me repeat myself, SIMPLE, this was just the starting point.
>> >
>> > niether 'simple' or 'starting point' equate to 'ugly' or 'shit'
>> > though do they. even simple scripts deserve error checking and
>> > a managable layout.
>> >
>> > I wasn't pointing that out to make you feel bad but to give you a
>> > leg up in better script writing ...
>> >
>> > >
>> > > The error was caused due to a field being created after there were
>> > > already rows in the table.
>> >
>> > that *shouldn't* cause you any errors. the most likely reason it
>> > did is your scripts assumption of the physical field order of your
>> table.
>> >
>> > I would recommend not using mysql_fetch_array() instead switch to
>> > mysql_fetch_assoc() and reference the elements in the returned array
>> > by name rather than by number - this has 2 advantages:
>> >
>> > 1. you won't get bitten by fields that were added to the table after
>> > the script was written.
>> > 2. the output you generate using the returned array is alot more
>> > understandable:
>> >
>> > e.g. $row['name'] as compared to $row[0]
>> >
>> > >
>> > > It works like a dream and now I will correct the errors you pointed
>> > > out and which you assumed I didn't know and which had no relevance to
>> > > my query after I stated so boldly that it was simple.
>> >
>> > a. I merely assumed that you *may* not be aware of the things I pointed
>> > out, if you are aware of those points then there was really no harm
>> done,
>> > if you weren't then you would have been armed some new info ...
>> >
>> > b. you can't control the answer, only the question, stop trying :-)
>> >
>> > >
>> > > Thanks
>> >
>> > ...
>> >
>>

attached mail follows:


Maybe I should clarify. When I use a windows path (c:\whatever) I get an
error that it can't find the path. In Linux the same code works fine
(/usr/local/whatever).

Here is all the relevent info.

Warning: opendir(f:\downloads\): failed to open dir: Invalid argument in
c:\web\index.php on line 30

***** This is line 30 - if ( $handle = opendir ( $page ) )

This is the code:

$page = "f:\\downloads";
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined

$display = searchdir($page);

$num = count($display);
$i = 0;

for($i = 0; $i <= $num; $i++) { echo $i." ".$display[$i]."<br>"; }

function searchdir ( $page , $maxdepth = -1 , $mode = "FILES" , $d = 0 ) {
   if ( substr ( $page , strlen ( $page ) - 1 ) != '\\' ) { $page .= '\\' ;
}
   $dirlist = array () ;
   if ( $mode != "FILES" ) { $dirlist[] = $page ; }
   if ( $handle = opendir ( $page ) )
   {
       while ( false !== ( $file = readdir ( $handle ) ) )
       {
           if ( $file != '.' && $file != '..' )
           {
               $file = $file ;
               if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) {
$dirlist[] = $file ; } }
               elseif ( $d >=0 && ($d < $maxdepth || $maxdepth < 0) )
               {
                   $result = searchdir ( $file . '\\' , $maxdepth , $mode ,
$d + 1 ) ;
                   $dirlist = array_merge ( $dirlist , $result ) ;
               }
       }
       }
       closedir ( $handle ) ;
   }
   if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
   return ( $dirlist ) ;
}

?>

> -----Original Message-----
> From: Jochem Maas [mailto:jochemiamjochem.com]
> Sent: January 7, 2007 10:25 AM
> To: Beauford
> Cc: PHP
> Subject: Re: [PHP] Windows directory listings
>
> Beauford wrote:
> > Hi,
> >
> > I am trying to write a script that reads a directory on
> Windows. All
> > the PHP functions I have looked at all seem to work with the Linux
> > dietary
>
> it sounds more like you have found an examples that show
> windows being used (i.e. windows file paths).
>
> > structure. Is there another way to do this.
>
> you must be reading a manual that only exists in your
> particular parallel universe, all relevant php function work
> in windows as well as linux:
>
> http://php.net/manual/en/ref.filesystem.php
> http://php.net/dir
>
> >
> > Thanks
> >
>
>
>

attached mail follows:


with regard to trolling - I'd don't *just* do that :-)

sometime I even get the answer to the question correct :-)
let's see if I can help ...

Beauford wrote:
> Maybe I should clarify. When I use a windows path (c:\whatever) I get an
> error that it can't find the path. In Linux the same code works fine
> (/usr/local/whatever).
>
> Here is all the relevent info.
>
> Warning: opendir(f:\downloads\): failed to open dir: Invalid argument in
> c:\web\index.php on line 30
>
> ***** This is line 30 - if ( $handle = opendir ( $page ) )
>
> This is the code:
>
> $page = "f:\\downloads";

you got this part right (escaping the backslash)

> // $mode : "FULL"|"DIRS"|"FILES"
> // $d : must not be defined
>
> $display = searchdir($page);
>
> $num = count($display);
> $i = 0;
>
> for($i = 0; $i <= $num; $i++) { echo $i." ".$display[$i]."<br>"; }
>
>
>
> function searchdir ( $page , $maxdepth = -1 , $mode = "FILES" , $d = 0 ) {
> if ( substr ( $page , strlen ( $page ) - 1 ) != '\\' ) { $page .= '\\' ;}

this if statement will run given the value of $page, it's not needed AFAIKT.
then again I can't see it causing problems.

btw: php defines a constant DIRECTORY_SEPARATOR automatically which may help you
make your code more portable, and save you having to think/worry about the blacksdlashing
'problem'.

> $dirlist = array () ;
> if ( $mode != "FILES" ) { $dirlist[] = $page ; }

right here I suggest adding a check using is_dir() and is_readable() on the $page var.
for now stick in a bit of debug code ...

echo '<pre>';
var_dump($path, is_dir($path), is_readable($path));
echo '</pre>';

I'm guessing that is_readable() is going to return false, which would point
the fact that either the drive or the directory is not readable by the webserver
process (you don't mention whether you are running via a the webserver but I assume you
are given the output your generating include a '<br>') - the situation maybe compounded
by the fact that F: is actually a mapped drive of some sorts (I have no idea
what kind of trouble this could cause).

> if ( $handle = opendir ( $page ) )
> {
> while ( false !== ( $file = readdir ( $handle ) ) )
> {
> if ( $file != '.' && $file != '..' )
> {
> $file = $file ;
> if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) {
> $dirlist[] = $file ; } }
> elseif ( $d >=0 && ($d < $maxdepth || $maxdepth < 0) )
> {
> $result = searchdir ( $file . '\\' , $maxdepth , $mode ,
> $d + 1 ) ;
> $dirlist = array_merge ( $dirlist , $result ) ;
> }
> }
> }
> closedir ( $handle ) ;
> }
> if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
> return ( $dirlist ) ;
> }
>
> ?>
>
>> -----Original Message-----
>> From: Jochem Maas [mailto:jochemiamjochem.com]
>> Sent: January 7, 2007 10:25 AM
>> To: Beauford
>> Cc: PHP
>> Subject: Re: [PHP] Windows directory listings
>>
>> Beauford wrote:
>>> Hi,
>>>
>>> I am trying to write a script that reads a directory on
>> Windows. All
>>> the PHP functions I have looked at all seem to work with the Linux
>>> dietary
>> it sounds more like you have found an examples that show
>> windows being used (i.e. windows file paths).
>>
>>> structure. Is there another way to do this.
>> you must be reading a manual that only exists in your
>> particular parallel universe, all relevant php function work
>> in windows as well as linux:
>>
>> http://php.net/manual/en/ref.filesystem.php
>> http://php.net/dir
>>
>>> Thanks
>>>
>>
>>
>

attached mail follows:


 

> -----Original Message-----
> From: Jochem Maas [mailto:jochemiamjochem.com]
> Sent: January 7, 2007 8:35 PM
> To: Beauford
> Cc: 'PHP'
> Subject: Re: [PHP] Windows directory listings
>
> with regard to trolling - I'd don't *just* do that :-)
>
> sometime I even get the answer to the question correct :-)
> let's see if I can help ...
>
> Beauford wrote:
> > Maybe I should clarify. When I use a windows path
> (c:\whatever) I get
> > an error that it can't find the path. In Linux the same code works
> > fine (/usr/local/whatever).
> >
> > Here is all the relevent info.
> >
> > Warning: opendir(f:\downloads\): failed to open dir:
> Invalid argument
> > in c:\web\index.php on line 30
> >
> > ***** This is line 30 - if ( $handle = opendir ( $page ) )
> >
> > This is the code:
> >
> > $page = "f:\\downloads";
>
> you got this part right (escaping the backslash)
>
> > // $mode : "FULL"|"DIRS"|"FILES"
> > // $d : must not be defined
> >
> > $display = searchdir($page);
> >
> > $num = count($display);
> > $i = 0;
> >
> > for($i = 0; $i <= $num; $i++) { echo $i." ".$display[$i]."<br>"; }
> >
> >
> >
> > function searchdir ( $page , $maxdepth = -1 , $mode =
> "FILES" , $d = 0 ) {
> > if ( substr ( $page , strlen ( $page ) - 1 ) != '\\' ) {
> $page .=
> > '\\' ;}
>
> this if statement will run given the value of $page, it's not
> needed AFAIKT.
> then again I can't see it causing problems.

This makes no difference. I took it out before and got the same error.

> btw: php defines a constant DIRECTORY_SEPARATOR automatically
> which may help you make your code more portable, and save you
> having to think/worry about the blacksdlashing 'problem'.
>
> > $dirlist = array () ;
> > if ( $mode != "FILES" ) { $dirlist[] = $page ; }
>
> right here I suggest adding a check using is_dir() and
> is_readable() on the $page var.
> for now stick in a bit of debug code ...
>
> echo '<pre>';
> var_dump($path, is_dir($path), is_readable($path)); echo '</pre>';

I checked the NTFS permissions and they are fine, and the local directory
displays fine. By this I mean the directory where this script is.

So if the script is in c:\test I can read c:\test, c:\test\test2.
c:\test\test3, ../test2. etc. It only happens when I go outside of the
current drive.

So if I put $page = "test", or $page = "test3", or $page = "../" they will
all work. As soon as I add a drive letter, it gives me the error. Even on
the local machine.

I am trying to access a networked drive, but I have a share on the PC where
the script is . May this is the issue. Is there a way to use a UNC path?
 
> I'm guessing that is_readable() is going to return false,
> which would point the fact that either the drive or the
> directory is not readable by the webserver process (you don't
> mention whether you are running via a the webserver but I
> assume you are given the output your generating include a
> '<br>') - the situation maybe compounded by the fact that F:
> is actually a mapped drive of some sorts (I have no idea what
> kind of trouble this could cause).
>
>
>
> > if ( $handle = opendir ( $page ) )
> > {
> > while ( false !== ( $file = readdir ( $handle ) ) )
> > {
> > if ( $file != '.' && $file != '..' )
> > {
> > $file = $file ;
> > if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) {
> > $dirlist[] = $file ; } }
> > elseif ( $d >=0 && ($d < $maxdepth ||
> $maxdepth < 0) )
> > {
> > $result = searchdir ( $file . '\\' , $maxdepth ,
> > $mode , $d + 1 ) ;
> > $dirlist = array_merge ( $dirlist , $result ) ;
> > }
> > }
> > }
> > closedir ( $handle ) ;
> > }
> > if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
> > return ( $dirlist ) ;
> > }
> >
> > ?>
> >
> >> -----Original Message-----
> >> From: Jochem Maas [mailto:jochemiamjochem.com]
> >> Sent: January 7, 2007 10:25 AM
> >> To: Beauford
> >> Cc: PHP
> >> Subject: Re: [PHP] Windows directory listings
> >>
> >> Beauford wrote:
> >>> Hi,
> >>>
> >>> I am trying to write a script that reads a directory on
> >> Windows. All
> >>> the PHP functions I have looked at all seem to work with
> the Linux
> >>> dietary
> >> it sounds more like you have found an examples that show windows
> >> being used (i.e. windows file paths).
> >>
> >>> structure. Is there another way to do this.
> >> you must be reading a manual that only exists in your particular
> >> parallel universe, all relevant php function work in
> windows as well
> >> as linux:
> >>
> >> http://php.net/manual/en/ref.filesystem.php
> >> http://php.net/dir
> >>
> >>> Thanks
> >>>
> >>
> >>
> >
>
> --
> PHP General Mailing List (http://www.php.net/) To
> unsubscribe, visit: http://www.php.net/unsub.php
>
>
>

attached mail follows:


Hi List

I have been given a rather urgent problem to solve for one of our clients. I
have to be able to connect to a server that deals with a section of the travel
industry and send and receive XML data. The API is quite poorly written and I am
finding it hard to get sense out of the companies help desk. I would appreciate
the help of the list in getting me pointed in the right direction.

The API expects a custom header and then a request. I have built the header and
I think it is OK. The request is an XML request and this is where I believe I am
having problems. I am getting an error response from the server telling me I
have invalid XML.

I am really stumped with the XML part. I have no idea how to code this section
and it appears what I am doing is not correct. I have spent days searching the
net looking for clues and so far have not succeeded.

I would appreciate help and guidance. If anyone needs any more information
please do not hesitate to ask.

This is what I have so far (note I have hidden usernames and passwords)

<?php

$url = "stagingxml.infosys.de";
$port = "10816";

/*
* HTTP Header Components
* Each part of the custom header is defined in the API document
*/

$length = "Content-Length: 502";
$a_encoding = "Accept-Encoding: gzip";
$t_encoding = "Transfer-Encoding: identity";
$accessmode = "Accessmode: agency";
$accessid = "Accessid: XXXXXXX XXXXXXX_layout";
$accept = "Accept: application/xml";
$charset = "Accept-Charset: iso-8859-1, utf-8";
$host = $test_url;
$session = "Session: ";
$api = "Api-Version: 3.4";
$connection = "Connection: Close";
$authorization = "Authorization: A Base 64 representation of username, password";
$authmode = "Authmode: pwd";

/*
* Build HTTP Header to use in CURLOPT_HTTPHEADER
*/

$headers[] = $length;
$headers[] = $a_encoding;
$headers[] = $t_encoding;
$headers[] = $accessmode;
$headers[] = $accessid;
$headers[] = $accept;
$headers[] = $charset;
$headers[] = $session;
$headers[] = $api;
$headers[] = $connection;
$headers[] = $authorization;
$headers[] = $authmode;

$xmlstr = '<?xml version="1.0" encoding="UTF-8"?><fareRequest da="false"><vcrs/><fareTypes/><tourOps/><flights><flight depApt="FRA" dstApt="LON" depDate="2007-01-26"/></flights><paxes><pax surname="Smith" firstname="John" dob="1945-12-12" gender="M"/></paxes><paxTypes/><options><limit>20</limit><offset>0</offset><waitOnList><waitOn>ALL</waitOn></waitOnList></options><coses/></fareRequest>';

$curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_PORT, $port);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, urlencode($xmlstr));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        
        curl_setopt($curl, CURLOPT_TIMEOUT, 40);
        curl_setopt($curl, CURLOPT_VERBOSE, 1);

        $response = curl_exec($curl);
                if(curl_errno($curl))
                {
                        print curl_error($curl);
                }
                else
                {
                curl_close($curl);
                }
        
        print "$response\n\n\n";

?>

I thank you in advance for any help.

Regards,
Richard Luckhurst
Exodus Systems - Sydney, Australia.
rluckhurstresmaster.com

attached mail follows:


Richard Luckhurst wrote:
> Hi List
>
> I have been given a rather urgent problem to solve for one of our clients. I
> have to be able to connect to a server that deals with a section of the travel
> industry and send and receive XML data. The API is quite poorly written and I am
> finding it hard to get sense out of the companies help desk. I would appreciate
> the help of the list in getting me pointed in the right direction.
>
> The API expects a custom header and then a request. I have built the header and
> I think it is OK. The request is an XML request and this is where I believe I am
> having problems. I am getting an error response from the server telling me I
> have invalid XML.
>
> I am really stumped with the XML part. I have no idea how to code this section
> and it appears what I am doing is not correct. I have spent days searching the
> net looking for clues and so far have not succeeded.
>
> I would appreciate help and guidance. If anyone needs any more information
> please do not hesitate to ask.
>
> This is what I have so far (note I have hidden usernames and passwords)
>
> <?php
>
> $url = "stagingxml.infosys.de";
> $port = "10816";
>
> /*
> * HTTP Header Components
> * Each part of the custom header is defined in the API document
> */
>
> $length = "Content-Length: 502";

The way I see it your Content-Length is wrong - the
length of your request in this instance would 380 bytes,
based on the length of $xmlstr. but that's probably not right
either.

I imagine you need to set Content-Length dynamically,
assuming curl doesn't do that for you ...

as a side note: why bother setting all these vars then stricking
them in an array - why not just stick the strings directly in the array?
additionally if you don't need to use double quotes (for variable
interpolation) single quotes are [marginally] faster [in theory] because
no variable interpolation is attempted on them.

e.g.

$headers = array(
        'Accept-Encoding: gzip',
        'Transfer-Encoding: identity',
        'Accessmode: agency',
        'Accessid: XXXXXXX XXXXXXX_layout',
        'Accept: application/xml',
        // etc
);

> $a_encoding = "Accept-Encoding: gzip";

not related to your current issue, but are your really accepting
a gzip'ed reply? this might cause you headaches once you have the
current problem solved.

> $t_encoding = "Transfer-Encoding: identity";
> $accessmode = "Accessmode: agency";
> $accessid = "Accessid: XXXXXXX XXXXXXX_layout";
> $accept = "Accept: application/xml";
> $charset = "Accept-Charset: iso-8859-1, utf-8";
> $host = $test_url;
> $session = "Session: ";
> $api = "Api-Version: 3.4";
> $connection = "Connection: Close";
> $authorization = "Authorization: A Base 64 representation of username, password";
> $authmode = "Authmode: pwd";
>
> /*
> * Build HTTP Header to use in CURLOPT_HTTPHEADER
> */
>
> $headers[] = $length;
> $headers[] = $a_encoding;
> $headers[] = $t_encoding;
> $headers[] = $accessmode;
> $headers[] = $accessid;
> $headers[] = $accept;
> $headers[] = $charset;
> $headers[] = $session;
> $headers[] = $api;
> $headers[] = $connection;
> $headers[] = $authorization;
> $headers[] = $authmode;
>
> $xmlstr = '<?xml version="1.0" encoding="UTF-8"?><fareRequest da="false"><vcrs/><fareTypes/><tourOps/><flights><flight depApt="FRA" dstApt="LON" depDate="2007-01-26"/></flights><paxes><pax surname="Smith" firstname="John" dob="1945-12-12" gender="M"/></paxes><paxTypes/><options><limit>20</limit><offset>0</offset><waitOnList><waitOn>ALL</waitOn></waitOnList></options><coses/></fareRequest>';
>
> $curl = curl_init();
> curl_setopt($curl, CURLOPT_URL, $url);
> curl_setopt($curl, CURLOPT_PORT, $port);
> curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
> curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
> curl_setopt($curl, CURLOPT_POST, 1);
> curl_setopt($curl, CURLOPT_POSTFIELDS, urlencode($xmlstr));

I am guessing that the urlencoded $xmlstr should be given a POST parameter name,
what that name is I don't know but the previous line should look something like
this (*I think*):

curl_setopt($curl, CURLOPT_POSTFIELDS, array('xml' => urlencode($xmlstr)));

you might consider point the curl request to a script you control,
so that you can see exactly what the request is sending.

        e.g. $url = 'http://yourdomain.tld/your-curl-request-test.php';

... and have your-curl-request-test.php write all it's recieved headers, etc
to a log file.

> curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
>
> curl_setopt($curl, CURLOPT_TIMEOUT, 40);
> curl_setopt($curl, CURLOPT_VERBOSE, 1);
>
> $response = curl_exec($curl);
> if(curl_errno($curl))
> {
> print curl_error($curl);
> }
> else
> {
> curl_close($curl);
> }
>
> print "$response\n\n\n";
>
> ?>
>
> I thank you in advance for any help.
>
>
>
> Regards,
> Richard Luckhurst
> Exodus Systems - Sydney, Australia.
> rluckhurstresmaster.com
>

attached mail follows:


Hi Jochem,

Thanks very much for your help. I now have the application working. Just for
anyone elses interest here are a few comments.

>> $length = "Content-Length: 502";

JM> The way I see it your Content-Length is wrong - the
JM> length of your request in this instance would 380 bytes,
JM> based on the length of $xmlstr. but that's probably not right
JM> either.

JM> I imagine you need to set Content-Length dynamically,
JM> assuming curl doesn't do that for you ...

Yes curl does it for you I have discovered. So I removed this Content-Length and
found that it is now dynamically generated.

JM> as a side note: why bother setting all these vars then stricking
JM> them in an array - why not just stick the strings directly in the array?
JM> additionally if you don't need to use double quotes (for variable
JM> interpolation) single quotes are [marginally] faster [in theory] because
JM> no variable interpolation is attempted on them.

Because I was being a bit lazy and wanted to see more of what was going on. Of
course you are right and I have now cleaned up my code as you have suggested.

>> $a_encoding = "Accept-Encoding: gzip";

JM> not related to your current issue, but are your really accepting
JM> a gzip'ed reply? this might cause you headaches once you have the
JM> current problem solved.

Yeah this gzip is a real pain. The API specifies either a gzipped or a
compressed data transfer. Some of the returns from the server, in Germany, can
be quite large so I guess the developers wanted to save some bandwidth by
compressing the data. I have just discovered that if I leave the
Accept-Encoding: gzip out all together then the whole process works with the
data returned in plain uncompressed text :-)

>> curl_setopt($curl, CURLOPT_POSTFIELDS, urlencode($xmlstr));

JM> I am guessing that the urlencoded $xmlstr should be given a POST parameter name,
JM> what that name is I don't know but the previous line should look something like
JM> this (*I think*):

JM> curl_setopt($curl, CURLOPT_POSTFIELDS, array('xml' => urlencode($xmlstr)));

This was where I had suspected I was having trouble. What I did find was that
the whole thing now works just by removing the urlencode all together. It
appears that the Content-Length was the problem all along and once that was
fixed and the urlencode was removed everything was fine.

JM> you might consider point the curl request to a script you control,
JM> so that you can see exactly what the request is sending.

JM> e.g. $url = 'http://yourdomain.tld/your-curl-request-test.php';

JM> ... and have your-curl-request-test.php write all it's recieved headers, etc
JM> to a log file.

Probably a good idea for debugging.

Thanks for your help.

Regards,
Richard Luckhurst
Product Development
Exodus Systems - Sydney, Australia.
rluckhurstresmaster.com

attached mail follows:


Can someone help me figure out why I can't run this on MySQL. I get a
syntax error.

list($qh,$num) = dbQuery("SELECT password AS passwd1,
$DATABASE_PASSWORD_FUNCTION('$password') AS passwd2 ".

"FROM $USER_TABLE WHERE username='$username'");

$data = dbResult($qh);

attached mail follows:


JD wrote:
> Can someone help me figure out why I can't run this on MySQL. I get a
> syntax error.
>
> list($qh,$num) = dbQuery("SELECT password AS passwd1,
> $DATABASE_PASSWORD_FUNCTION('$password') AS passwd2 ".
>
> "FROM $USER_TABLE WHERE username='$username'");
>
> $data = dbResult($qh);

You've already posted this on the php-db list and had two responses. No
need to send it to all php mailing lists you can find.

--
Postgresql & php tutorials
http://www.designmagick.com/

attached mail follows:


bruce wrote:
> chris...
>
> sure there is.. alot of people don't subscribe to other lists. if you're one
> who does, simply ignore his post.

And if the poster looked at either of the responses he received and
replied to the questions asked, then he'd get a much better response.

http://marc.theaimsgroup.com/?t=116821281800003&r=1&w=2

If the OP didn't get a response at all, then hey go for it but since he
got two responses within 5 minutes of the original post and then decided
to post on another list within 10 minutes, then yeh I will criticize.

--
Postgresql & php tutorials
http://www.designmagick.com/

attached mail follows:


Hi all. I've a question regarding PHP's ODBC support.

Here's the situation:

We've a PHP app that uses ODBC to talk to a MS SQL server. Its original home
was on a server that used the OpenLink ODBC driver, which was a POS, so we
build an abstraction wrapper around the subset of PHP's ODBC functions that
we were able to use to make it usable. The internal code for a query is
built on odbc_exec, odbc_fetch_row, and odbc_result. The main interesting
part is that the original driver didn't allow for named results, so instead
we have a small string parser that reads the incoming SQL query, extracts the
field names, and then uses that to map the numeric result indexes to their
field name. Kinda clunky, but worked well and used only a minimal ODBC
footprint.

That worked fine on their old system. However, the client then moved from a
Windows IIS server to Apache and PHP 5.1.6 on a Linux box, but still talking
to an MS SQL server on a Windows box. We migrated our test environment to
the same; Linux/Apache/PHP 5.1 talking to MS SQL on a Windows box over the
network. Our system uses the unix_ODBC and freetds stack for ODBC
connectivity, and that works fine.

On the client's system, it works fine except for a few odd cases.
Specifically, on a few queries that pull data from large text fields the
query may hang. It seems to reliably hang on certain records only, and only
after those records have been edited. It seems that when updating a record,
there is a small chance of something happening to that record and it then not
working thereafter. A PHP test script run from the command line freezes,
while the same query run directly on the SQL server returns almost instantly.

The client has been in contact with their ODBC driver vendor (they're using a
commercial driver), and the vendor's response is that we're not using ODBC
correctly. Specifically, they say:

-----
I followed the ODBC calls in your odbc trace file and I got error
"Invalid Descriptor Index" on SQLGetData as well. I know we normally
don't handle the retrieval of large dataset like Text using SQLGetData
as your application is doing. I'm in the research of whether the way
your application does is valid or not.
-----

They then followed up with:

-----
We have done some research on this issue. We realized that your
application is binding all the columns for the resultset and then use
SQLGetData. This is not the correct way to do. You can either use bind
column for result set and then print out the data in the bound buffer,
or use SQLGetData to get the unbound resultset.
-----

They then include some sample code that is all in C.

Now I'll be honest and say I don't quite follow what they're talking about. I
do not claim to be an ODBC guru, but SQLGetData is a lower-level operation,
SQL level or C level I don't know, but not something that happens in PHP code
as far as I am aware. Are they saying there's a bug in PHP's
odbc_fetch_row()? Or is it a bug in their driver if it can't handle whatever
it is odbc_fetch_row() does internally? Or should we be using odbc_result()
instead of odbc_fetch_row() if we're dealing with a text field rather than a
varchar or int?

I am confused, and would appreciate assistance in becoming less confused. :-)
Thanks.

--
Larry Garfield AIM: LOLG42
larrygarfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson

attached mail follows:


no real answer, but ...

Larry Garfield wrote:
> Hi all. I've a question regarding PHP's ODBC support.
>
> Here's the situation:
>
> We've a PHP app that uses ODBC to talk to a MS SQL server. Its original home
> was on a server that used the OpenLink ODBC driver, which was a POS, so we
> build an abstraction wrapper around the subset of PHP's ODBC functions that
> we were able to use to make it usable. The internal code for a query is
> built on odbc_exec, odbc_fetch_row, and odbc_result. The main interesting
> part is that the original driver didn't allow for named results, so instead
> we have a small string parser that reads the incoming SQL query, extracts the
> field names, and then uses that to map the numeric result indexes to their
> field name. Kinda clunky, but worked well and used only a minimal ODBC
> footprint.
>
> That worked fine on their old system. However, the client then moved from a
> Windows IIS server to Apache and PHP 5.1.6 on a Linux box, but still talking
> to an MS SQL server on a Windows box. We migrated our test environment to
> the same; Linux/Apache/PHP 5.1 talking to MS SQL on a Windows box over the
> network. Our system uses the unix_ODBC and freetds stack for ODBC
> connectivity, and that works fine.
>
> On the client's system, it works fine except for a few odd cases.
> Specifically, on a few queries that pull data from large text fields the
> query may hang. It seems to reliably hang on certain records only, and only
> after those records have been edited. It seems that when updating a record,
> there is a small chance of something happening to that record and it then not
> working thereafter. A PHP test script run from the command line freezes,
> while the same query run directly on the SQL server returns almost instantly.

...

>
> Now I'll be honest and say I don't quite follow what they're talking about. I
> do not claim to be an ODBC guru, but SQLGetData is a lower-level operation,
> SQL level or C level I don't know, but not something that happens in PHP code
> as far as I am aware. Are they saying there's a bug in PHP's
> odbc_fetch_row()? Or is it a bug in their driver if it can't handle whatever
> it is odbc_fetch_row() does internally?
> Or should we be using odbc_result()
> instead of odbc_fetch_row() if we're dealing with a text field rather than a
> varchar or int?

the way I read it odbc_result() is just an alternative way of doing what you
do with odbc_fetch_row() - I can't see any reason why doing it with odbc_result()
would suddenly make it work - nonetheless it might be worth trying it just to rule
it out.

with regard to wanting results returned in a 'named' fashion, does the new setup still
not allow use of odbc_fetch_array() instead of odbc_fetch_row()? not that I see any logic
in that solving the issue, again it might be worth trying to see if it does.

I don't know much about MSSQL, or whether 'text' is an actual field type, but maybe
this function offers a wayout?:

        http://php.net/manual/en/function.odbc-binmode.php

are the php versions on the 2 systems you mention exactly the same? (you
mention 5.1 and 5.1.6) this could be a clue to the problem.

lastly I don't suppose that it possible for you to switch to using the MSSQL
specific php extension? [http://php.net/mssql] it might offer a better/faster connection
to the MSSQL server as well as making the issue go away.

>
> I am confused, and would appreciate assistance in becoming less confused. :-)
> Thanks.
>

attached mail follows:


On Sunday 07 January 2007 8:26 pm, Jochem Maas wrote:

> > Now I'll be honest and say I don't quite follow what they're talking
> > about. I do not claim to be an ODBC guru, but SQLGetData is a lower-level
> > operation, SQL level or C level I don't know, but not something that
> > happens in PHP code as far as I am aware. Are they saying there's a bug
> > in PHP's
> > odbc_fetch_row()? Or is it a bug in their driver if it can't handle
> > whatever it is odbc_fetch_row() does internally?
> > Or should we be using odbc_result()
> > instead of odbc_fetch_row() if we're dealing with a text field rather
> > than a varchar or int?
>
> the way I read it odbc_result() is just an alternative way of doing what
> you do with odbc_fetch_row() - I can't see any reason why doing it with
> odbc_result() would suddenly make it work - nonetheless it might be worth
> trying it just to rule it out.
>
> with regard to wanting results returned in a 'named' fashion, does the new
> setup still not allow use of odbc_fetch_array() instead of
> odbc_fetch_row()? not that I see any logic in that solving the issue, again
> it might be worth trying to see if it does.

Honestly I've not tried. (I also don't have the wrapper code in front of me
at the moment. <g>) That could be a nice thing to simplify for performance,
but I suspect that if the problem is with odbc_fetch_row() then
odbc_fetch_array() will have the same bug.

> I don't know much about MSSQL, or whether 'text' is an actual field type,
> but maybe this function offers a wayout?:
>
> http://php.net/manual/en/function.odbc-binmode.php

No, that looks like it's for binary data. "Text" is a MS SQL field for
huge-ass text fields, essentially similar to the MySQL field of the same name
(at least at an API level). We also tried playing with odbc_longreadlen()
and setting MS SQL's TEXTSIZE and TEXTLENGTH parameters to no avail.

> are the php versions on the 2 systems you mention exactly the same? (you
> mention 5.1 and 5.1.6) this could be a clue to the problem.

It's either both 5.1.6 or 5.1.6 live and 5.1.4 devel. (I don't recall what
our exact version is atm.) We're in the process of upgrading our server
soon, and I'm not sure what it will have. Probably 5.2, just to keep life
interesting. :-)

> lastly I don't suppose that it possible for you to switch to using the
> MSSQL specific php extension? [http://php.net/mssql] it might offer a
> better/faster connection to the MSSQL server as well as making the issue go
> away.

I don't believe the client allows direct MSSQL connections. Besides, the
MSSQL functions still require an ODBC driver underneath, so if the problem is
with the ODBC driver then that won't change anything.

--
Larry Garfield AIM: LOLG42
larrygarfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson

attached mail follows:


Well - first I would turn off display errors and turn on log errors.
Then - well there is always the error suppressor () - but I personally
don't like it. You could also create a custom error handler... And I
wonder if mysqli supports exceptions...

http://www.php.net/manual/en/ref.errorfunc.php
http://www.php.net/~helly/php/ext/spl/

Respectfully,
Ligaya Turmelle
Systems Analyst
Guamcell Communications
Phone: (671)689-2377
-----Original Message-----
From: Richard Morris [mailto:richardhddbroker.com]
Sent: Saturday, January 06, 2007 4:29 AM
To: php-generallists.php.net
Subject: [PHP] How to suppress error messages when using 'new
mysqli(...)'

Hi,

I am having this problem that I hope can be worked around. I make a
connection to our MySQL database using the object version of mysqli. If
access is denied because of an incorrect username or password, mysqli
displays an error. Is there any way to suppress the error message?

Here is the code I am using as a test case:

<?php
   $db = null;

   $db = new mysqli('localhost', 'user', 'badpass', 'test');

   if (mysqli_connect_errno()) {
     echo "Database connection error.\n\n";
     exit();
   }

   echo "Connection successful.\n\n";
?>

This is the output I get:

PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user
'user''localhost' (using password: YES) in /home/richard/dbtest.php on
line 4

Warning: mysqli::mysqli(): (28000/1045): Access denied for user
'user''localhost' (using password: YES) in /home/richard/dbtest.php on
line 4 An error occurred while trying to connect to the database.

I was expecting this:

An error occurred while trying to connect to the database.

Is there a way to prevent the error messages from being display so that
the error can be handled in a nicer manner?

Thank you.

--
Richard Morris
HDD Broker, Inc.

     Toll-Free: +1 866 960-3331
International: +1 250 474-6022
           Fax: +1 250 474-6099
        E-Mail: richardhddbroker.com
      Web Site: www.hddbroker.com

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php