[PHP] Re: [PHP-DEV] toString() in SimpleXML?

2005-02-17 Thread Leendert Brouwer
Hi Marcus,
Marcus Boerger wrote:
  having a function __toString() would interfere with the mapping ideas of
SimpleXML. However it is there internally so you simply do one of the
following:
php -r '$x=SimpleXML_load_string("blablabla"); echo 
$x, "\n"; var_dump((string)$x);'
I'm aware of that. But how would something like nodeValue() interfere 
with the mapping ideas behind SimpleXML? IMHO, casts are not intuitive 
in a development process, especially not when you need them as much as 
you would in SimpleXML. Now it just feels like working around a problem 
when coding.

further questions please to [EMAIL PROTECTED]
as you wish..
Monday, February 14, 2005, 1:23:44 PM, you wrote:

Hi,

I have a feature request. Maybe it would be a good idea to have a 
toString() or perhaps nodeValue() method in SimpleXML's SimpleXMLElement 
class? It might make it more obvious that the element is still a 
SimpleXMLElement object when you want to actually use it (when you print 
it, the value automagically casts to a string internally, so users might 
think that it will be casted to a string when you directly access it 
without a specified property/method, which is not the case). I know that 
the docs say that you should cast it to a string when you want to do a 
comparison, but apart from that just being an example, maybe my 
suggestion is a more obvious one to notice?

regards,

Leendert



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


[PHP] Re: saving resource objects

2003-12-17 Thread Leendert

"Michael Lewis" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I posted this on the PHP-DB list and then realized it was a more general
> question about PHP than DB so I am posting it here also hoping someone can
> help.
>
> I have a fairly common problem that I have not been able to find the
> solution for in the documentation and FAQs. I have to access a MSSQL box
> from a LAMP box using PHP. That part works fine (thank you freetds.org). I
> need to display results from user queries 10 at a time with the basic NEXT
> and BACK logic. I can use the mssql_data_seek function to move amongst the
> record set. The problem is how do I save the results variable between web
> page updates? I cannot save the record set variable in my session because
it
> always returns as zero. Consider the following code:
>
>  session_start();
> include("localsettings.php");
> $s = mssql_connect($Server, $User, $Pass) or die("Couldn't connect to SQL
> Server on $Server");
> mssql_select_db($SDB, $s) or die("Couldn't open database $SDB");
> $sql="select * from products where prod_id='95038'";
> $ress=mssql_query($sql) or die(mssql_get_last_message());
> $_SESSION['ress']=$ress;
> print $ress."\n";
> $ress=$_SESSION['ress'];
> print $ress."\n";
> ?>
>
> The first time I print RESS is comes back as RESOURCE OBJECT #12, the
second
> time as 0. When I look in the session file, it is zero.
>
> Help!
>
> How can I pass this variable and its contents so they are usable to the
next
> web page?
>
> Thanks in advance.
>
> Michael


Although still in beta phase, you might want to have a look at what SRM
could do for you. www.vl-srm.net

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



[PHP] Re: BLOB - PHP Peformance DB vs. Web server Opinions

2003-12-04 Thread Leendert

"Ahbaid Gaffoor" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thanks to all who helped with my earlier questions on pulling BLOB data
> out of Oracle using PHP.
>
> I am however finding that performance is slow when downloading huge
> files from the database.
>
> A typical 2Meg GIF file being downloaded from Oracle via. PHP is taking
> about thirty seconds.
>
> Everything (database, web server, development box) are all on a 100
> Megabit Switched ethernet setup.
>
>
> 1) Are there any pitfalls or guidelines when working with BLOBs and web
> apps?
>
> 2) Is there any advice for or against storing images as blobs in a
> database? Or is it better to store them on the web server file system?
>
> So far I am finding the web server file system to be faster, but I tend
> to think that it is less manageable from a relational data perspective.
>
> thoughts?
>
> thanks
>
> Ahbaid


As 1) and 2) are closely related, I'll write the answer to both at once. The
only real advantage to storing files in BLOBs that I can think of is
replication. If your database is replicated over X amount of servers, you'd
have to write seperate procedures to replicate the images that go with the
database, as they are not stored in the DBMS. That can be quite annoying if
you consider all the issues that come with it (locking etc.). Application
logic (or, right, manageability) is another issue that jumps to mind
(especially when trying to write generic database handling stuff), but
minor, and often you can overcome that problem by abstracting filesystem
logic in its design. In some situations, it's simply impractical. Imagine a
page with thumbnails, where the data for the thumbnails has to be pulled
from database BLOBs. You'd have to have a seperate request to the database
for every thumbnail on the page, as you have to spit out different headers
for images (you'd get those  a lot).
If you didn't store them in a BLOB, you could simply output the paths to the
images and they'd be fetched from the webserver's filesystem. Another
disadvantage is that doing a lot of updating operations on BLOB fields tends
to fragment your harddisk pretty fast. Another issue, as already mentioned,
is speed. While it should be said that speed depends on how the DBMS
optimizes the search operations thus will vary between database servers, it
is usually just faster to fetch a file directly from the filesystem without
interference of the DBMS. In high-traffic situations, you're likely to
notice the speed difference. There are probably more disadvantages, but this
is what I can come up with from the top of my head. So, if you must depend
on replication, that's a good reason to choose BLOBs for storage. In any
other case I'd suggest you don't.


Regards,

Leendert Brouwer
Freelance consultancy
http://www.daholygoat.com

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



Re: [PHP] Re: Checking for empty values sent from a form

2003-03-06 Thread Leendert
You usually don't want spaces either

foreach($_POST as $val)
{
if(strlen(trim($val)) < 1)
// do what you want
}


"Rick Emery" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> foreach($HTTP_POST_VARS as $val)
>   if($val=="")
>   {
>   do something
>   }
> - Original Message -
> From: "shaun" <[EMAIL PROTECTED]>
> To: <>
> Sent: Thursday, March 06, 2003 7:45 AM
> Subject: [PHP] Re: Checking for empty values sent from a form
>
>
> thanks for your reply but I was wondering if there was a way to check
> through all of the form entries with an easier way that
>
> if ($_POST['your_input_name'] == '' || $_POST['your_input_name'] == '' ||
> $_POST['your_input_name'] == '' || $_POST['your_input_name'] == '' ) //etc
>   // field is empty
>
> this would be particularly useful for forms with lots of fields...
>
>
> "Niels Andersen" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Since input from a form are strings, you can check like this:
> >
> > if ($_POST['your_input_name'] == '')
> >   // field is empty
> >
> > "Shaun" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > > Is there an easy way to scan through an array of values sent from a
form
> > to
> > > see if any of them are empty?
> > >
> > >
> >
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>



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



[PHP] Re: xml_set_character_data_handler logic

2002-09-30 Thread Leendert Brouwer

Cardinal from IRC answered my question. It turns out that when you indent
your childs with tabs, it sees those tabs as cdata of the root element. I
had the following XML file:

sampleDBName
sampleUser
localhost


The tabs in front of the child elements were treated as CDATA of the
 root node.


"Leendert" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> "Leendert" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > It appears that:
> >
> > xml_set_character_data_handler($parser, 'handleData');
> >
> > calls handleData() 3 times per element. Does anyone know the reason
behind
> > this? Sounds like that could be very inefficient.
> >
> >
>
> FYI, this is the code I'm using:
>
>  class XMLSettingsParser
> {
>  var $settingsFile;
>  var $xmlData;
>  var $parser;
>  var $tempElementName;
>
>  function XMLSettingsParser($settingsFile)
>  {
>   $this->SettingsFile = $settingsFile;
>
>   $this->xmlData = implode('', file($settingsFile));
>
>   $this->parser = xml_parser_create();
>   xml_set_object($this->parser, &$this);
>
>   xml_set_element_handler($this->parser, 'handleStartElement',
> 'handleEndElement');
>   xml_set_character_data_handler($this->parser, 'handleData');
>
>   xml_parse($this->parser, $this->xmlData);
>   xml_parser_free($this->parser);
>  }
>
>  function handleStartElement($parser, $name, $attribs)
>  {
>   $this->tempElementName = $name;
>  }
>
>  function handleEndElement()
>  {}
>
>  function handleData($parser, $data)
>  {
>   //if(!defined($this->tempElementName))
>define($this->tempElementName, $data);
>  }
> }
> ?>
>
> It gives me 2 notices per element that the constant is already defined,
> while it shouldn't. When I do use the conditional
> if(!defined($this->tempElementName))  it works fine of course. But it
should
> work in the first place.
> Note: you need error_reporting(E_NOTICE); on to see the error.
>
>
>
>



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




[PHP] Re: xml_set_character_data_handler logic

2002-09-30 Thread Leendert

"Leendert" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> It appears that:
>
> xml_set_character_data_handler($parser, 'handleData');
>
> calls handleData() 3 times per element. Does anyone know the reason behind
> this? Sounds like that could be very inefficient.
>
>

FYI, this is the code I'm using:

SettingsFile = $settingsFile;

  $this->xmlData = implode('', file($settingsFile));

  $this->parser = xml_parser_create();
  xml_set_object($this->parser, &$this);

  xml_set_element_handler($this->parser, 'handleStartElement',
'handleEndElement');
  xml_set_character_data_handler($this->parser, 'handleData');

  xml_parse($this->parser, $this->xmlData);
  xml_parser_free($this->parser);
 }

 function handleStartElement($parser, $name, $attribs)
 {
  $this->tempElementName = $name;
 }

 function handleEndElement()
 {}

 function handleData($parser, $data)
 {
  //if(!defined($this->tempElementName))
   define($this->tempElementName, $data);
 }
}
?>

It gives me 2 notices per element that the constant is already defined,
while it shouldn't. When I do use the conditional
if(!defined($this->tempElementName))  it works fine of course. But it should
work in the first place.
Note: you need error_reporting(E_NOTICE); on to see the error.





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




[PHP] xml_set_character_data_handler logic

2002-09-30 Thread Leendert

It appears that:

xml_set_character_data_handler($parser, 'handleData');

calls handleData() 3 times per element. Does anyone know the reason behind
this? Sounds like that could be very inefficient.



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