Re: [PHP] Coordenates latitude / longitude on PHP - SOLVED

2006-03-03 Thread Ruben Rubio Rey

It wasn't so hard!
I ll post the solution, so everyone ll be able to do it

function getlocationcoords($lat, $lon, $width, $height)
{
  $lat=$lat*20;   
  $lon=$lon*28; 
  $x = (($lon + 180) * ($width / 360));  
  $y = ((($lat * -1) + 90) * ($height / 180));

  return array("x"=>round($x),"y"=>round($y+3500));
}

$lat -> Latitude
$lon -> Longitude
$width -> Image's width (Where u are going to represent the data)
$height -> Image's height (Where u are going to represent the data)


This is the zoom of the data
$lat=$lat*20;   
$lon=$lon*28; 
If the data is lo flat (for example), u can fix it writting bigger 
values on the data that is multiplying.


$x = (($lon + 180) * ($width / 360));  
$y = ((($lat * -1) + 90) * ($height / 180));

This translates lat / lon to cardinal data. I found it on the net.


return array("x"=>round($x+VALUEONE),"y"=>round($y+3500));
If u puts the rights values on VALUEONE or 3500, u will be able to 
center the coordenates on the image.


Done!
:)

By Tk421

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



[PHP] help with nl2br

2006-03-03 Thread canobit canobit
I have cobbled the following code that when it retrieves the data from
Mysql, the data is displayed with no line breaks which results in one large
paragraph. I have been trying for quite awhile without sucess to get
nl2br working with this code. The original data is entered by the user via a
textarea form.

Any help would be much apreciated...I am still fairly new at programming and
it probably shows...

Thanks
TD.


 0) {
 // yes
 // print them one after another
echo "";

 while($row = mysql_fetch_row($result)) {

echo "";
echo ".$row[1]";
echo "";
echo ".$row[2]";
echo "  \n";
echo "  \n";

 }

}
else {
 // no
 // print status message
 echo "No rows found!";
}

// free result set memory
mysql_free_result($result);

// close connection
mysql_close($connection);


?>


[PHP] DOMElement::setAttribute() manual example question

2006-03-03 Thread Andreas Korthaus

Hi!

I've a question regarding the example in DOMElement::setAttribute() 
chapter of the PHP manual: http://de3.php.net/dom-domelement-setattribute


There, an attribute is added to an element this way:

createElement("root");
$newnode = $doc->appendChild($node);
$newnode->setAttribute("align", "left");
echo $doc->saveXML();
?>

$doc->createElement() returns the created DOMElement, 
$doc->appendChild() returns the appended DOMNode. Isn't this the same 
object? Is it a reference?


I'm asking, because the following works too:

createElement("root");
$node->setAttribute("align", "left");
$doc->appendChild($node);
echo $doc->saveXML();
?>


I like the 2nd example more, because first you create an object 
(DOMElement), add some attributes to the object and after that append it 
somewhere to the DOM tree. The 1st example creates a new DOMElement 
object, appends it to the DOM tree, and adds the attributes not to the 
created object, but to another object (the DOMNode appended to the 
tree), which seems to be a reference to the original object.


Why does the manual prefer the (IMO less intuitive) 1st way? Is there a 
problem with the 2nd way?



best regards
Andreas

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



[PHP] Beware of OS X PHP security update...

2006-03-03 Thread Marcus Bointon
The OS X security update issued yesterday includes a PHP 'fix', by  
which they mean that it installs PHP 4.4.1. If you have installed PHP  
5 from elsewhere, it will get trashed along with your PEAR setup.  
PEAR is now completely confused or me and just crashes when I try to  
do anything.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



RE: [PHP] LDAP confusion

2006-03-03 Thread jblanchard
[snip] I vaguely recall you couldn't do an anonymous bind to an active 
directory system - you had to properly authenticate before you could do 
a search.

You didn't include the bind stuff so I can't tell if that's the problem
:)
[/snip]

I thought that I was not doing an anonymous bind, until I changed the
username to something that I know did not exist. The bind occurred (or
appeared to) anyhow.

if(!$ds=ldap_connect("foo")){
echo "did not connect";
}else {
echo "connection successful";
}
$un = "user";
$upw = "pass";
echo "connect result is " . $ds . "";
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);

if ($ds) { 
   echo "Binding ..."; 
   if(!$r=ldap_bind($ds, $un, $upd)){
echo "unable to verify";
   }else{
echo "verified";
   }

The result is always "verified".

This should be a really simple operation.

1. user enters name and password
2. if bind is successful redirect them properly
3. else give them a message about incorrect login.

I really do not need to search the AD or any of that (I may want to
install phpldapadmin at some point though).

I feel as if I am missing something very simple, I have always been able
to connect to everything with PHP. Can anyone help me with this please?

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



[PHP] Re: DOMElement::setAttribute() manual example question

2006-03-03 Thread Rob

Andreas Korthaus wrote:

Hi!

I've a question regarding the example in DOMElement::setAttribute() 
chapter of the PHP manual: http://de3.php.net/dom-domelement-setattribute


There, an attribute is added to an element this way:

createElement("root");
$newnode = $doc->appendChild($node);
$newnode->setAttribute("align", "left");
echo $doc->saveXML();
?>

$doc->createElement() returns the created DOMElement, 
$doc->appendChild() returns the appended DOMNode. Isn't this the same 
object? Is it a reference?


I'm asking, because the following works too:

createElement("root");
$node->setAttribute("align", "left");
$doc->appendChild($node);
echo $doc->saveXML();
?>


I like the 2nd example more, because first you create an object 
(DOMElement), add some attributes to the object and after that append it 
somewhere to the DOM tree. The 1st example creates a new DOMElement 
object, appends it to the DOM tree, and adds the attributes not to the 
created object, but to another object (the DOMNode appended to the 
tree), which seems to be a reference to the original object.


Why does the manual prefer the (IMO less intuitive) 1st way? Is there a 
problem with the 2nd way?


Both ways are perfectly valid. $node and $newnode refer to the same 
object. It was written the 1st way to demonstrate the return value of 
appendChild(), because in many cases people create the element differently.


i.e.

$newnode = $doc->appendChild($doc->createElement("root"));
or
$newnode = $doc->appendChild(new DOMElement("root"));

Also, in the event $node is created using the new DOMElement syntax:

$node = new DOMElement("root");

the node is read only and must be appended into the tree before it can 
be modified, so the example just tries to be neutral here regarding the 
syntax used.


Rob

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



Re: [PHP] help with nl2br

2006-03-03 Thread Max Schwanekamp

canobit canobit wrote:

I have cobbled the following code that when it retrieves the data from
Mysql, the data is displayed with no line breaks which results in one large
paragraph. I have been trying for quite awhile without sucess to get
nl2br working with this code. The original data is entered by the user via a
textarea form.

 while($row = mysql_fetch_row($result)) {
echo "";
echo ".$row[1]";
echo "";
echo ".$row[2]";
echo "  \n";
echo "  \n";  


There is no nl2br in your code sample, so I'm assuming you want to put 
$row[2] through it?  It's about as simple as nl2br($row[2]).  If that 
doesn't work, then perhaps you should post sample code that is failing, 
and the output you get, along with the output you're expecting.


All that said, you might want to invest some time in learning a DB 
abstraction layer such as ADODb or PEAR::DB (there are lots of others). 
 You'll commonly find convenience functions to do things like output 
query results into an HTML table.  Why waste time debugging the wheel?


--
Max Schwanekamp
http://www.neptunewebworks.com/

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



Re: [PHP] help with nl2br

2006-03-03 Thread canobit canobit
Thanks Pablo, that did the trick with one minor change, I had to remove the
. in the quotations as it is was leading the first line of text with a .

echo "" . nl2br($row[2]) . "";

TD.


On 3/3/06, Pablo M. Rivas <[EMAIL PROTECTED]> wrote:
>
> Hello canobit:
>
> Did you try echo "." . nl2br($row[1]) . ""; ??
>
>
> On 3/2/06, canobit canobit < [EMAIL PROTECTED]> wrote:
> >
> > I have cobbled the following code that when it retrieves the data from
> > Mysql, the data is displayed with no line breaks which results in one
> > large
> > paragraph. I have been trying for quite awhile without sucess to get
> > nl2br working with this code. The original data is entered by the user
> > via a
> > textarea form.
> >
> > Any help would be much apreciated...I am still fairly new at programming
> > and
> > it probably shows...
> >
> > Thanks
> > TD.
> >
> >
> >  >
> > // set database server access variables:
> > $host = "localhost";
> > $user = "develop";
> > $pass = "";
> > $db = "bio";
> >
> > // open connection
> > $connection = mysql_connect($host, $user, $pass) or die ("Unable to
> > connect!");
> >
> > // select database
> > mysql_select_db($db) or die ("Unable to select database!");
> >
> > // create query
> > $query = "SELECT * FROM main";
> >
> > // execute query
> > $result = mysql_query($query) or die ("Error in query: $query.
> > ".mysql_error());
> >
> > // see if any rows were returned
> > if (mysql_num_rows($result) > 0) {
> >  // yes
> >  // print them one after another
> > echo "";
> >
> > while($row = mysql_fetch_row($result)) {
> >
> > echo "";
> > echo ".$row[1]";
> > echo "";
> > echo ".$row[2]";
> > echo "  \n";
> > echo "  \n";
> >
> > }
> >
> > }
> > else {
> > // no
> > // print status message
> > echo "No rows found!";
> > }
> >
> > // free result set memory
> > mysql_free_result($result);
> >
> > // close connection
> > mysql_close($connection);
> >
> >
> > ?>
> >
> >
>
>
> --
> Pablo M. Rivas. http://www.r3soft.com.ar http://www.tres-erres.com.ar
> ---
>


Re: [PHP] Only 4 of 5...

2006-03-03 Thread Gustav Wiberg
- Original Message - 
From: "John Nichel" <[EMAIL PROTECTED]>

To: "PHP General" 
Sent: Friday, March 03, 2006 2:30 AM
Subject: Re: [PHP] Only 4 of 5...



Gustav Wiberg wrote:

Hi there!

What's wrong here??



You're pulling the first row here


if (intval($frmIDModel)>0) {

?>
Visa telefonbilder för :
0) {

   $dbNameManufacturer = $dbArray["nameManufacturer"];

 ?>
 Visa telefonbilder för :
 
Alla telefonbilder i arkivet:


So now there are only 4 rows left when you loop thru them here.


   while ($dbArray = mysql_fetch_array($querys)) {
 $dbIDPic = $dbArray["IDPic"];
 $dbPicNameSmall = $dbArray["picNameSmall"];
 ?>
 height="130">

 

I have 5 posts in the table, but the images shown are only four! Why?

/G




--
By-Tor.com
...it's all about the Rush
http://www.by-tor.com

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


Thanx, I got feedback on this one yesterday! :) Thanx anyway!

/G

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



[PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Mark Steudel
I was wondering what the general rule on using the global driective versus
passing in a variable by reference, why you should or shouldn't, etc.
 
e.g.
 
function ()
{
global $db;
 
$res =& $db->query( "SQL");
}
 
or
 
function ( &$db )
{
 
$res =& $db->query( "SQL");
}

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



Re: [PHP] Re: DOMElement::setAttribute() manual example question

2006-03-03 Thread Gustav Wiberg
- Original Message - 
From: "Rob" <[EMAIL PROTECTED]>

To: "Andreas Korthaus" <[EMAIL PROTECTED]>
Cc: 
Sent: Friday, March 03, 2006 4:43 PM
Subject: [PHP] Re: DOMElement::setAttribute() manual example question



Andreas Korthaus wrote:

Hi!

I've a question regarding the example in DOMElement::setAttribute() 
chapter of the PHP manual: http://de3.php.net/dom-domelement-setattribute


There, an attribute is added to an element this way:

createElement("root");
$newnode = $doc->appendChild($node);
$newnode->setAttribute("align", "left");
echo $doc->saveXML();
?>

$doc->createElement() returns the created DOMElement, $doc->appendChild() 
returns the appended DOMNode. Isn't this the same object? Is it a 
reference?


Check out:
http://de3.php.net/manual/en/function.dom-domdocument-createelement.php
( This function creates a new instance of class DOMElement. This node will 
not show up in the document unless it is inserted with e.g. 
DOMNode->appendChild().)


I really don't understand WHY your next example is working...

/G








I'm asking, because the following works too:

createElement("root");
$node->setAttribute("align", "left");
$doc->appendChild($node);
echo $doc->saveXML();
?>


I like the 2nd example more, because first you create an object 
(DOMElement), add some attributes to the object and after that append it 
somewhere to the DOM tree. The 1st example creates a new DOMElement 
object, appends it to the DOM tree, and adds the attributes not to the 
created object, but to another object (the DOMNode appended to the tree), 
which seems to be a reference to the original object.


Why does the manual prefer the (IMO less intuitive) 1st way? Is there a 
problem with the 2nd way?


Both ways are perfectly valid. $node and $newnode refer to the same 
object. It was written the 1st way to demonstrate the return value of 
appendChild(), because in many cases people create the element 
differently.


i.e.

$newnode = $doc->appendChild($doc->createElement("root"));
or
$newnode = $doc->appendChild(new DOMElement("root"));

Also, in the event $node is created using the new DOMElement syntax:

$node = new DOMElement("root");

the node is read only and must be appended into the tree before it can be 
modified, so the example just tries to be neutral here regarding the 
syntax used.


Rob

--
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



Re: [PHP] help with nl2br

2006-03-03 Thread canobit canobit
>
> 
> All that said, you might want to invest some time in learning a DB
> abstraction layer such as ADODb or PEAR::DB (there are lots of others).
>   You'll commonly find convenience functions to do things like output
> query results into an HTML table.  Why waste time debugging the wheel?
> --
> Max Schwanekamp
> http://www.neptunewebworks.com/
>



Thanks Max, I will further look into look into this. PEAR::DB looks
interesting!
TD


Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Gustav Wiberg
- Original Message - 
From: "Mark Steudel" <[EMAIL PROTECTED]>

To: 
Sent: Friday, March 03, 2006 7:46 PM
Subject: [PHP] Coding Practice: Use global $var or pass in by refernce



I was wondering what the general rule on using the global driective versus
passing in a variable by reference, why you should or shouldn't, etc.

e.g.

function ()
{
   global $db;

   $res =& $db->query( "SQL");
}

or

function ( &$db )
{

   $res =& $db->query( "SQL");
}

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


Hi!

My oponion is that is insane to use global variables. The main drawback with 
global variables is that is very easy to mix up variables, and keep track of 
what variable belongs to what. So an advice: Don't use it!


/G

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



Re: [PHP] Re: DOMElement::setAttribute() manual example question

2006-03-03 Thread Rob

Gustav Wiberg wrote:


Check out:
http://de3.php.net/manual/en/function.dom-domdocument-createelement.php
( This function creates a new instance of class DOMElement. This node 
will not show up in the document unless it is inserted with e.g. 
DOMNode->appendChild().)


I really don't understand WHY your next example is working...


Every example so far has called appendChild(). The only difference has 
been when at which point it is called to append the element and how the 
element to append has been created.


Rob

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



Re: [PHP] Re: APC and PHP 5.1.2

2006-03-03 Thread steve
Thanks for that! It meant that I should look in other directions which
helped me figure out the problem. Can you try again with:

apc.optimization=1

I think the optimizer is what dies with php 5.1.x. It works for me now
if I don't have that line. :) Too bad APC can't work with Zend
Optimizer, since I think the fact that ZPS and its successors work
faster (and with a lower load average) is partly because of its
optimizations like loop unrolling, etc.

 Personally I found it odd that Zend made it separate, since it slows
down normal PHP execution, and only shines with the opcode cache (and
it does). I do get that it is an "optimizer" and therefore tries to
fool people into using it in order to get their loader for their
encoder in wide distribution. With PHP 6 looking like it will have an
opcode cache by default, I'd think they would want it to be theirs so
as to make everything more compatible with their other products, but I
bet there is some interal reason why that won't happen.

On 3/2/06, Jens Kleikamp <[EMAIL PROTECTED]> wrote:
> steve wrote:
> > You know not what you ask!! I'm going to have to wait a bit before I
> > do that. Currently using Apache 2, and the config files would need to
> > be different, etc., so I'll have to choose a webserver I can take down
> > for a longer time. :(
> >
> > What I did try was different versions of PHP (All using FastCGI &
> > APC-dev) (if this even helps):
> >
> > 5.1.2 -- Failed
> > 5.1.1 -- Failed
> > 5.0.5 -- Success
> >
> > -steve--
> >
> > On 3/2/06, Rasmus Lerdorf <[EMAIL PROTECTED]> wrote:
> >> It probably does.  I have never tried it against the Fastcgi sapi.  Try
> >> it with the Apache module version to rule this out.
> >>
> >> -Rasmus
> >>
> >
>
> Your script works fine for me on linux, php 5.1.2 FastCGI + apc-dev.
>
> Jens
>
> --
> 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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Andreas Korthaus

Hi Gustav!

Gustav Wiberg wrote:

My oponion is that is insane to use global variables. The main drawback 
with global variables is that is very easy to mix up variables, and keep 
track of what variable belongs to what. So an advice: Don't use it!


Ok, so what's your recommendation to solve the problem with using a DB 
class in many other objects/methodes? Think of a DB class:


class DB {...}

And a lot of classes which want to use the DB class:

class Foo {
  function saveChangesInDb() {...}
}

class Bar {
  function saveChangesInDb() {...}
}

- You can use a global "$db = new DB..." and pass it to every class/methode,

- you can make $db "global" in each methode,

- you can create a new instance ("new DB") in every methode (but you 
usually only want a single DB-connection per script, and where do you 
pass config-data to access the DB?) or


- use a factory/singleton, which is not so much better than a global 
variable (and again, what about config-data?).



So what's the way you'd recommend and why?


best regards
Andreas

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



Re: [PHP] Re: DOMElement::setAttribute() manual example question

2006-03-03 Thread Gustav Wiberg


- Original Message - 
From: "Rob" <[EMAIL PROTECTED]>

To: "Gustav Wiberg" <[EMAIL PROTECTED]>
Cc: "Andreas Korthaus" <[EMAIL PROTECTED]>; 
Sent: Friday, March 03, 2006 8:04 PM
Subject: Re: [PHP] Re: DOMElement::setAttribute() manual example question



Gustav Wiberg wrote:


Check out:
http://de3.php.net/manual/en/function.dom-domdocument-createelement.php
( This function creates a new instance of class DOMElement. This node 
will not show up in the document unless it is inserted with e.g. 
DOMNode->appendChild().)


I really don't understand WHY your next example is working...


Every example so far has called appendChild(). The only difference has 
been when at which point it is called to append the element and how the 
element to append has been created.


Rob

Maybe it is so that the objects propertys is created in a certain order 
undependet of the script order?


/G

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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Luis Magaña

I would go for:

- you can create a new instance ("new DB") in every methode (but you
  usually only want a single DB-connection per script, and where do you
  pass config-data to access the DB?) or

This way the code keeps well organized and about the use of only one 
connection I wouldn't worry too much since usually one thread/process is 
created per script called, so if this is a multiuser application you end 
up with several connections anyway, besides I think PHP reuses the 
connections when possible so the performance of your application does 
not seem affected at all.


I use it, works perfectly with big databases and several users.

Regards.

Andreas Korthaus wrote:

Hi Gustav!

Gustav Wiberg wrote:

My oponion is that is insane to use global variables. The main 
drawback with global variables is that is very easy to mix up 
variables, and keep track of what variable belongs to what. So an 
advice: Don't use it!


Ok, so what's your recommendation to solve the problem with using a DB 
class in many other objects/methodes? Think of a DB class:


class DB {...}

And a lot of classes which want to use the DB class:

class Foo {
  function saveChangesInDb() {...}
}

class Bar {
  function saveChangesInDb() {...}
}

- You can use a global "$db = new DB..." and pass it to every 
class/methode,


- you can make $db "global" in each methode,

- you can create a new instance ("new DB") in every methode (but you 
usually only want a single DB-connection per script, and where do you 
pass config-data to access the DB?) or


- use a factory/singleton, which is not so much better than a global 
variable (and again, what about config-data?).



So what's the way you'd recommend and why?


best regards
Andreas



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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Gustav Wiberg


- Original Message - 
From: "Andreas Korthaus" <[EMAIL PROTECTED]>

To: ; "Gustav Wiberg" <[EMAIL PROTECTED]>
Sent: Friday, March 03, 2006 8:53 PM
Subject: Re: [PHP] Coding Practice: Use global $var or pass in by refernce



Hi Gustav!

Gustav Wiberg wrote:

My oponion is that is insane to use global variables. The main drawback 
with global variables is that is very easy to mix up variables, and keep 
track of what variable belongs to what. So an advice: Don't use it!


Ok, so what's your recommendation to solve the problem with using a DB 
class in many other objects/methodes? Think of a DB class:


class DB {...}

And a lot of classes which want to use the DB class:

class Foo {
  function saveChangesInDb() {...}
}

class Bar {
  function saveChangesInDb() {...}
}

- You can use a global "$db = new DB..." and pass it to every 
class/methode,


- you can make $db "global" in each methode,

- you can create a new instance ("new DB") in every methode (but you 
usually only want a single DB-connection per script, and where do you pass 
config-data to access the DB?) or


- use a factory/singleton, which is not so much better than a global 
variable (and again, what about config-data?).



So what's the way you'd recommend and why?


best regards
Andreas

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


Hi Andreas!

I don't have that much experience with classes, but wouldn't it work to:

1. make a connection to the db like $db = , and then pass around 
this variable?


2. Extend the DB - class, so the saveChangesInDb()  - function in the 
Foo-class would be an extension from the DB-class

? (I think this works to extend a class in PHP right?)

3 . Use already existing classes for db...http://www.phpclasses.org/ PHP 
Scripts / Databases


I hope this'll help!

/G

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



[PHP] Re: Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Jens Kleikamp

Mark Steudel wrote:

I was wondering what the general rule on using the global driective versus
passing in a variable by reference, why you should or shouldn't, etc.
 
e.g.
 
function ()

{
global $db;
 
$res =& $db->query( "SQL");

}
 
or
 
function ( &$db )

{
 
$res =& $db->query( "SQL");

}



or

function foo ()
{
$db = & $GLOBALS['database'];
$res = & $db->query();
}

or

function foo ()
{
$res = & $GLOBALS['database']->query();
}

Just some more possibilities...


cheers
Jens

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



[PHP] Re: APC and PHP 5.1.2

2006-03-03 Thread Jens Kleikamp

steve wrote:

Thanks for that! It meant that I should look in other directions which
helped me figure out the problem. Can you try again with:

apc.optimization=1




Your script also seems to work on my sytem with optimization=1.

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



[PHP] Swedish sourgeforge for php-prg

2006-03-03 Thread Gustav Wiberg

Hi there!

I wonder as a swedish PHP-programmer if there are any sites like 
sourgeforge.net but in swedish?


/G

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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Robert Cummings
On Fri, 2006-03-03 at 14:53, Andreas Korthaus wrote:
>
> - use a factory/singleton, which is not so much better than a global 
> variable (and again, what about config-data?).

I use a global configuration to register database connection params.
InterJinn uses something like the following:

$GLOBALS['interJinn']['databases'] = array
(
'carnageWeb' => array
(
'type' => 'mysql',
'host' => 'wocmud.org',
'user' => 'me',
'password' => 'noyou',
'db'   => 'carnage_web'
),

'carnage' => array
(
'host' => 'wocmud.org',
'user' => 'me',
'password' => 'notyouagain',
'db'   => 'carnage'
),

'carnageForum' => array
(
'host' => 'wocmud.org',
'user' => 'me',
'password' => 'notyouyetagain',
'db'   => 'carnage_forum'
),

'default'   => 'carnageWeb',
);

This is consumed by the database manager which is a singleton/factory
that uses connection pooling.

getServiceRef( 'dbManager' );

$db = &$mDb->getConnectionRef();
$db->query( 'blah blah blah' );

$db2 = &$mDb->getConnectionRef();
$db2->query( 'bleh bleh bleh' );

$db3 = &$mDb->getConnectionRef( 'carnageForum' );
$db3->query( 'bleh bleh bleh' );

$db->free();
$db2->free();
$db3->free();
?>

In this way all database connections are named such that if something
changes in the future, whether it be the name of the database, the type
of database server, the port, whatever, my code shouldn't need to change
-- only the configuration. Additionally since I retrieve from a pool, I
only ever use as many connections as I need at a time. Be that 1 or 3 or
5. Additionally I know that when I retrieve a second database instance
it's not going to clobber the query from the first request.

I advocate use of the $GLOBALS array for configuration information that
remains static and only when the purpose is clearly defined and well
named such that you can be very sure that you won't run into naming
conflicts in the near future. This is why I use an interJinn sub array
within the globals to segregate InterJinn specific configuration vars.
I'd advocate using constants but they don't support arrays, or at least
not as far back as I maintain compatibility. Why the PHP guys didn't
foresee constant array values is anyone's guess *lol*.

You'll also notice I retrieve the factory/singleton by means of named
service. This avoids most of that interface/inheritance bullshit that
Java gets mired in (and PHP5 has embraced *hahah*). As long as the
expected methods exist then any class can be dropped in as a replacement
via the service registry, whether it extends, implements, burps, or
farts the original class -- or not :)

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.  |
`'

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



[PHP] Help with Acrostix

2006-03-03 Thread Jay Contonio
I am using acrostix so I can add text and photos to an existing pdf.

So far I have the text working with this,

pages[0], $lines);

$image = ax_load_jpeg_file("dingo.jpg", 1, 1, 72);
ax_add_page_elements($doc->pages[0], $image);

header("Content-type: application/pdf");
ax_output_pdf_file($doc);

?>

But the image doesn't addand I've tried multiple ways. Can any of
you help? Here's the function list for acrostix,

http://www.conradish.net/acrostix/functions.html

And the site for acrostix,

http://chernyshevsky.blogspot.com/

--
Jay Contonio
http://www.jcontonio.com/

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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread tedd

So what's the way [using Globals] you'd recommend and why?

best regards
Andreas


Andreas:

I have to agree with Gustav on this -- I very seldom use Globals. I 
might use one for debugging, but not for finished code. Their use 
simply creates problems in porting code, keeping things modular, and 
maintenance.


Perhaps I'm fortunate, but I usually find a way around using Globals. 
And since I've been coding in PHP, I've never been forced to use them.


tedd

--

http://sperling.com

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



Re: [PHP] Re: APC and PHP 5.1.2

2006-03-03 Thread steve
Really? Now I am confused on why I'd be having a problem and you
aren't. I even deleted the php.ini file and made a new one that only
contained this:

extension=apc.so
apc.optimization=1

and it still failed. At least I have it working without the second line.

My phpinfo() has this as the configure line (why the quotes?):

'./configure' '--with-mysqli' '--with-pdo' '--with-cli' '--with-gd'
'--with-dom' '--with-zlib' '--with-xml' '--with-openssl'
'--enable-mbstring=all' '--enable-inline-optimization'
'--enable-memory-limit' '--enable-exif' '--enable-fastcgi'
'--enable-force-cgi-redirect' '--without-pear'

Can you check yours?

Maybe there is a conflict with the modules compiled in and APC's
optimizer (though that sounds really strange). Maybe I'll try removing
all of them and recompile and see what happens...

Thanks Jens!

-steve-


On 3/3/06, Jens Kleikamp <[EMAIL PROTECTED]> wrote:
> steve wrote:
> > Thanks for that! It meant that I should look in other directions which
> > helped me figure out the problem. Can you try again with:
> >
> > apc.optimization=1
> >
>
>
> Your script also seems to work on my sytem with optimization=1.
>
> --
> 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



Re: [PHP] Beware of OS X PHP security update...

2006-03-03 Thread Geoff Martin


On 03/03/2006, at 11:15 PM, Marcus Bointon wrote:

The OS X security update issued yesterday includes a PHP 'fix', by  
which they mean that it installs PHP 4.4.1. If you have installed  
PHP 5 from elsewhere, it will get trashed along with your PEAR  
setup. PEAR is now completely confused or me and just crashes when  
I try to do anything.


Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk

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



I installed the update successfully, no effect on PHP 5.

Perhaps you need to look elsewhere

Geoff

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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Rafael

Andreas Korthaus wrote:

Hi Gustav!

Gustav Wiberg wrote:

My oponion is that is insane to use global variables. The main 
drawback with global variables is that is very easy to mix up 
variables, and keep track of what variable belongs to what. So an 
advice: Don't use it!



Ok, so what's your recommendation to solve the problem with using a DB 
class in many other objects/methodes? Think of a DB class:


class DB {...}

And a lot of classes which want to use the DB class:

class Foo {
  function saveChangesInDb() {...}
}

class Bar {
  function saveChangesInDb() {...}
}

- You can use a global "$db = new DB..." and pass it to every 
class/methode,


- you can make $db "global" in each methode,

- you can create a new instance ("new DB") in every methode (but you 
usually only want a single DB-connection per script, and where do you 
pass config-data to access the DB?) or


- use a factory/singleton, which is not so much better than a global 
variable (and again, what about config-data?).



So what's the way you'd recommend and why?


	IMHO, the only way a global variable would have sense is in an 
environment where you can be assured there's a "DBClass" $db instance, 
and that it would never ever be a $db var that's not a DBClass instance 
nor will $db ever be missing.  So, can you guarantee this at the present 
and to the end of times? :)


	I think it would be better to create an instance of $db whatever the 
script you need it, and pass it to every class-constructor as a 
byref-parameter; i.e.


  $db =& new DBClass();
  ···
  $class1 =& new Class1($db);
  ···
  $class2 =& new Class2($db);

	Now, if you insist on using global vars, then maybe, just maybe, it 
would be better to let that byref-param be optional, and check in the 
constructor for a global DBClass instance $db if no DBClass instance was 
given, but then again the problem would be pretty much the same.  Try 
not to rely on global vars, bear in mind that global vars almost always 
give too little info and do not reflect themselves on the function 
prototype --well, if you have a smart IDE/editor that understand PHPDoc 
comments (or something like that) and you do document their existance, 
it might not be that bad, but still try to avoid them.

--
Atentamente,
J. Rafael Salazar Magaña
Innox - Innovación Inteligente
Tel: +52 (33) 3615 5348 ext. 205 / 01 800 2-SOFTWARE
http://www.innox.com.mx

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



[PHP] Prepared statements

2006-03-03 Thread Julius Hacker
Hi,

so I need help again:
I want to use prepared statements to insert lots of data in my
MySQL-database.
For that I use foreach because I have an array containing all necessary
information.

Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and
mysql_stmt_bind_param.
In the foreach-loop I give the variables, which I bound with bind_param,
their values and want to execute the statement.

But now MySQL returns always an error.
It seems that the values I gave the variables in the loop aren't used
because I used bind_param before that.

In the example for mysql_bind_param they do it like me.
Is the example also wrong or do I have to consider something special?

--
Regards
Julius Hacker

http://www.julius-hacker.de
[EMAIL PROTECTED]

OpenPGP-Key-ID: 0x4B4A486E

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



[PHP] Mysql Rows

2006-03-03 Thread benifactor
i need to find a way to find out what number of a row is in a database...

for example:

//this is the database
Username: Chuck Password: adsasa
Username: jimmy Password: adsf
Username: stewart Password: dfds

the information i need is what row jimmy resides on..

this is what i tried:

function i_gun ($user) {
global $username;
$gun = mysql_query("select * from users");
while ($d = mysql_fetch_array($gun)) {
while($d[username] != $user) {
$i = $i + 1;
}
}
}

but it always returns 1. can sombody tell me what i am doing wrong or point me 
in the right direction in the manual? plase and thank you

Re: [PHP] Mysql Rows

2006-03-03 Thread Anthony Ettinger
define $1 = 0 outside your loop.

i'm curious why you are relying on row-order in the database?
Typically you'd have a PRIMARY KEY auto_increment for something like
this.


On 3/3/06, benifactor <[EMAIL PROTECTED]> wrote:
> i need to find a way to find out what number of a row is in a database...
>
> for example:
>
> //this is the database
> Username: Chuck Password: adsasa
> Username: jimmy Password: adsf
> Username: stewart Password: dfds
>
> the information i need is what row jimmy resides on..
>
> this is what i tried:
>
> function i_gun ($user) {
> global $username;
> $gun = mysql_query("select * from users");
> while ($d = mysql_fetch_array($gun)) {
> while($d[username] != $user) {
> $i = $i + 1;
> }
> }
> }
>
> but it always returns 1. can sombody tell me what i am doing wrong or point 
> me in the right direction in the manual? plase and thank you
>


--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

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



Re: [PHP] Prepared statements

2006-03-03 Thread Anthony Ettinger
are you executing the statement in your loop too?


On 3/3/06, Julius Hacker <[EMAIL PROTECTED]> wrote:
> Hi,
>
> so I need help again:
> I want to use prepared statements to insert lots of data in my
> MySQL-database.
> For that I use foreach because I have an array containing all necessary
> information.
>
> Before that foreach, I use mysqli_stmt_init, mysql_stmt_prepare and
> mysql_stmt_bind_param.
> In the foreach-loop I give the variables, which I bound with bind_param,
> their values and want to execute the statement.
>
> But now MySQL returns always an error.
> It seems that the values I gave the variables in the loop aren't used
> because I used bind_param before that.
>
> In the example for mysql_bind_param they do it like me.
> Is the example also wrong or do I have to consider something special?
>
> --
> Regards
> Julius Hacker
>
> http://www.julius-hacker.de
> [EMAIL PROTECTED]
>
> OpenPGP-Key-ID: 0x4B4A486E
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

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



[PHP] Re: APC and PHP 5.1.2

2006-03-03 Thread Jens Kleikamp

steve wrote:

Really? Now I am confused on why I'd be having a problem and you
aren't. I even deleted the php.ini file and made a new one that only
contained this:

extension=apc.so
apc.optimization=1

and it still failed. At least I have it working without the second line.

My phpinfo() has this as the configure line (why the quotes?):

'./configure' '--with-mysqli' '--with-pdo' '--with-cli' '--with-gd'
'--with-dom' '--with-zlib' '--with-xml' '--with-openssl'
'--enable-mbstring=all' '--enable-inline-optimization'
'--enable-memory-limit' '--enable-exif' '--enable-fastcgi'
'--enable-force-cgi-redirect' '--without-pear'

Can you check yours?

Maybe there is a conflict with the modules compiled in and APC's
optimizer (though that sounds really strange). Maybe I'll try removing
all of them and recompile and see what happens...



./configure \
--prefix=/usr/local/php5-fcgi \
--with-config-file-path=/etc/php5-fcgi \
--with-mysql=/usr \
--with-zlib \
--enable-fastcgi \
--enable-memory-limit \
--enable-force-cgi-redirect \
--enable-track-vars \
--without-pear \
--with-imap \
--with-imap-ssl \
--with-gd \
--enable-gd-native-ttf \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-freetype-dir=/usr \
--enable-pdo \
--enable-pdo_mysql \
--with-pdo_mysql \
--with-gettext \
--with-iconv \
--enable-mbstring=all \
--enable-mbregex \
--with-mime-magic=/usr/share/misc/file/magic.mime \
--with-dom \
--with-mcrypt


hth,
Jens




-steve-


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



Re: [PHP] CLI utility

2006-03-03 Thread Kevin Kinsey

John Nichel wrote:


Ray Cantwell wrote:


Hello again,
I was wondering if any of you knew of a good command line
utility for php5 on linux? The box i write on has no X-windows.

Ray.



A command line utility to do what?



Indeed.  Context might even indicate he's looking for
something to use to write his PHP scripts on a box
with no GUI.

In which case, the question is better avoided as it's
a terribly effective magnet for holy war.

Furthermore, I didn't choose the .sig below, it's randomly
generated by fortune(6), but it really speaks to me, heh

KDK

PS. "ed(1) is the standa"  nah. ;-)


--
Uncle Ed's Rule of Thumb:
Never use your thumb for a rule.
You'll either hit it with a hammer or get a splinter in it.

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



Re: [PHP] CLI utility

2006-03-03 Thread Ray Cantwell
Indeed i am looking for a tool to write my code with on a box that has 
no gui environment, However if a Jihad is going to ensue because of it, 
i shall withdraw my question, head bowed.

RTC

Kevin Kinsey wrote:


John Nichel wrote:


Ray Cantwell wrote:


Hello again,
I was wondering if any of you knew of a good command line
utility for php5 on linux? The box i write on has no X-windows.

Ray.



A command line utility to do what?



Indeed.  Context might even indicate he's looking for
something to use to write his PHP scripts on a box
with no GUI.

In which case, the question is better avoided as it's
a terribly effective magnet for holy war.

Furthermore, I didn't choose the .sig below, it's randomly
generated by fortune(6), but it really speaks to me, heh

KDK

PS. "ed(1) is the standa"  nah. ;-)




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



Re: [PHP] CLI utility

2006-03-03 Thread Kevin Kinsey

Ray Cantwell wrote:

Indeed i am looking for a tool to write my code with on a box that has 
no gui
environment, However if a Jihad is going to ensue because of it, i 
shall withdraw

my question, head bowed.
RTC





Well, kudos to you for discretion, which has been noted
as 'the better part of valor', indeed.

For our mutual edification, here are a few links relevant
to the discussion as it pertains to PHP in particular, from
a favorite forum of mine.

The classic:
  http://www.phpbuilder.com/board/showthread.php?t=10209798

The imitators:
  http://www.phpbuilder.com/board/showthread.php?t=10280025
  http://www.phpbuilder.com/board/showthread.php?t=10274550 (GPL version)
  http://www.phpbuilder.com/board/showthread.php?t=10255309
  http://www.phpbuilder.com/board/showthread.php?t=10253439
  http://www.phpbuilder.com/board/showthread.php?t=10298665
  http://www.phpbuilder.com/board/showthread.php?t=10256359

Regarding WYSIWYG editors:
  http://www.phpbuilder.com/board/showthread.php?t=10264772

For the Mac user:
  http://www.phpbuilder.com/board/showthread.php?t=10297539

I'd also recommend plugging such terms as "editor", "text editor",
"PHP IDE" and so on into a good search engine.

Finally, try reading this:  
  http://en.wikipedia.org/wiki/Editor_wars


--- for some background on why this question is so, um, politically
incorrect  (ahem), and try Googling the phrase "vi versus emacs"
to see that it's actually true.

Meanwhile, I'm off to unwedge my tongue, which seems to have
lodged itself firmly between my cheek and upper jaw

Use what you want, they'll make more,
  
	Kevin Kinsey


--
A wise man can see more from the bottom
of a well than a fool can from a mountain top.

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



Re: [PHP] Mysql Rows

2006-03-03 Thread benifactor
thank you. the table does have and id feild that auto increments, however if
you delete a user there will be a gap between the users between which would
not be what is not acurate enough. thank you for you help. simple fix. i
should have caught it.
- Original Message - 
From: "Anthony Ettinger" <[EMAIL PROTECTED]>
To: "benifactor" <[EMAIL PROTECTED]>
Cc: "php" 
Sent: Friday, March 03, 2006 3:52 PM
Subject: Re: [PHP] Mysql Rows


define $1 = 0 outside your loop.

i'm curious why you are relying on row-order in the database?
Typically you'd have a PRIMARY KEY auto_increment for something like
this.


On 3/3/06, benifactor <[EMAIL PROTECTED]> wrote:
> i need to find a way to find out what number of a row is in a database...
>
> for example:
>
> //this is the database
> Username: Chuck Password: adsasa
> Username: jimmy Password: adsf
> Username: stewart Password: dfds
>
> the information i need is what row jimmy resides on..
>
> this is what i tried:
>
> function i_gun ($user) {
> global $username;
> $gun = mysql_query("select * from users");
> while ($d = mysql_fetch_array($gun)) {
> while($d[username] != $user) {
> $i = $i + 1;
> }
> }
> }
>
> but it always returns 1. can sombody tell me what i am doing wrong or
point me in the right direction in the manual? plase and thank you
>


--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

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



Re: [PHP] Re: APC and PHP 5.1.2

2006-03-03 Thread Rasmus Lerdorf

Jens Kleikamp wrote:

steve wrote:

Thanks for that! It meant that I should look in other directions which
helped me figure out the problem. Can you try again with:

apc.optimization=1




Your script also seems to work on my sytem with optimization=1.


The optimizer doesn't work very well at this point.  It will get some 
attention soon I hope.


If you need to squeeze every bit of performance out of your code there 
are usually much bigger wins than an optimizer will give you in going 
through and cleaning things up.  The easy list of low-hanging 
optimization fruit are:


1. Check your include_path and your includes.  If you make heavy use of
   files in a directory on your include_path, make sure that path is
   first.  And yes, that means before "." as well.  In fact I wouldn't
   even put "." in your include_path, just use

  include './file.php';

   if you want to include from the current directory or relative to
   the current directory.  You are going to save quite a few stat calls
   by cleaning this up.

2. Minimize your use of include_once/require_once.  If you can clean
   up your dependencies and your include tree such that there is no
   question of double-inclusion anywhere everything will be much
   happier.  A redundant include is obviously going to waste useless
   cycles, but even if you don't hit the redundant case, the _once
   operations are optimized for the non-cached scenario and actually
   calls open() on every file which makes sense without an opcode cache
   because you are going to need the file opened, but with a cache you
   are going to get the opcodes from the cache and this becomes a
   useless extra open() syscall.

3. Try to avoid pushing things out of the compiler and into the
   executor.  That's a bit cryptic, but it basically means try to
   avoid dynamically defining functions and classes.

Good:  

Bad:   

   In the second case the foo class has to be defined at script runtime
   which is much slower than if it is unconditionally defined in the
   compiler.  Without an opcode cache this isn't much of an issue, of
   course since you have to run both stages, but with an opcode cache
   where you skip the compile phase and just feed the opcodes straight
   to the executor, the more you can handle when you compile the opcodes
   the faster your script will run because the executor has less work to
   do.

4. Make use of APC's apc_store/apc_fetch mechanism.  If you have any
   sort of large array of data you need often, stick it in shared memory
   with an apc_store() call.  For example, a typical thing you see in
   PHP applications is some sort of config.php file.  It might look
   like this:



   And then on every page you have:  include './config.php';

   This is very inefficient even though the actual file will be cached
   in the opcode cache, it still has to execute and create the array.
   You can cache the created array like this:

if(!$config = apc_fetch('config')) {
   include './config.php';
   apc_store('config',$config);
}

   Here we only include the config file and thus create the $config
   array if it isn't in the cache.  So this will only happen on the
   very first request.  From then on it will get pulled from the
   shared memory cache.

   If you look around there are usually a couple of candidates for
   this sort of caching in every application and it can make quite
   a difference for large arrays.  Try to avoid caching objects
   because they need to be serialized and unserialized in and out
   of the cache and you can only cache the properties anyway, so
   pull the data you want to cache into an array and cache that.

-Rasmus

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



[PHP] Is it better to return a multi-array, or an array of objects?

2006-03-03 Thread Daevid Vincent
I'm building a fairly large project. I've been trying to follow best
practices, but I'm a bit worried about performance. Using PHP 5.1 and mySQL
5.0.

I have product and company classes.

So when a user does a search of the database, is it better/faster/etc. to
return just a two dimensional associative array to populate an HTML table of
the results like: product name, product id, price, company name, company
phone, etc. (assume I'm only showing some of the total number of fields).

Or, should my SQL method return me an array of product objects, which then
inturn contain a company object? Keeping in mind, these objects are then a
complete snapshot of the database row they represent, along with other
fields and such that are created upon instantiation.

Does this make sense what I'm asking?

Are these things negligible?

Does it matter that I'm only showing say 10 fields of perhaps 50 or more
possible ones (that the classes and database would hold)?

My gut feeling is to use an array as it seems less overhead and "faster".
However the object versions seems to be more expandable and maintainable
perhaps. Although a bit more work due to all the method calls to pull out
the stuff to display in the HTML.

I could run timing tests, etc, but I only have like 10 products right now in
the database while I'm building, and without REAL world data, I think my
tests will be skewed.

Lets say that I expect several thousands to a hundred thousand or so people
searching the database via the web UI when this is finally completed.

ÐÆ5ÏÐ 

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



Re: [PHP] Is it better to return a multi-array, or an array of objects?

2006-03-03 Thread chris smith
On 3/4/06, Daevid Vincent <[EMAIL PROTECTED]> wrote:
> I'm building a fairly large project. I've been trying to follow best
> practices, but I'm a bit worried about performance. Using PHP 5.1 and mySQL
> 5.0.
>
> I have product and company classes.
>
> So when a user does a search of the database, is it better/faster/etc. to
> return just a two dimensional associative array to populate an HTML table of
> the results like: product name, product id, price, company name, company
> phone, etc. (assume I'm only showing some of the total number of fields).
>
> Or, should my SQL method return me an array of product objects, which then
> inturn contain a company object? Keeping in mind, these objects are then a
> complete snapshot of the database row they represent, along with other
> fields and such that are created upon instantiation.
>
> Does this make sense what I'm asking?
>
> Are these things negligible?
>
> Does it matter that I'm only showing say 10 fields of perhaps 50 or more
> possible ones (that the classes and database would hold)?
>
> My gut feeling is to use an array as it seems less overhead and "faster".
> However the object versions seems to be more expandable and maintainable
> perhaps. Although a bit more work due to all the method calls to pull out
> the stuff to display in the HTML.
>
> I could run timing tests, etc, but I only have like 10 products right now in
> the database while I'm building, and without REAL world data, I think my
> tests will be skewed.
>
> Lets say that I expect several thousands to a hundred thousand or so people
> searching the database via the web UI when this is finally completed.

I don't think you'll find much difference either way.. I wouldn't
return a whole object though - lots of memory usage there for a small
result set.

If you return an array of data, you have to firstly turn the results
into an array, then after you return it you have to go through the
array again to display the results.. so you're doubling up a little.

Then again - it depends on how your app is set up. Personally I use my
own API to fetch data so it returns an array, then the "front" can do
whatever with it (display html, display xml - doesn't matter to the
API).

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



Re: [PHP] LDAP confusion

2006-03-03 Thread chris smith
On 3/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> [snip] I vaguely recall you couldn't do an anonymous bind to an active
> directory system - you had to properly authenticate before you could do
> a search.
>
> You didn't include the bind stuff so I can't tell if that's the problem
> :)
> [/snip]
>
> I thought that I was not doing an anonymous bind, until I changed the
> username to something that I know did not exist. The bind occurred (or
> appeared to) anyhow.
>
> if(!$ds=ldap_connect("foo")){
> echo "did not connect";
> }else {
> echo "connection successful";
> }
> $un = "user";
> $upw = "pass";
> echo "connect result is " . $ds . "";
> ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
> ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
>
> if ($ds) {
>echo "Binding ...";
>if(!$r=ldap_bind($ds, $un, $upd)){
> echo "unable to verify";
>}else{
> echo "verified";
>}
>
> The result is always "verified".

>From the comments on www.php.net/ldap_bind:

I have found that if either  of the valuse for user or password are
blank, or as in my case a typo resulted in a blank user as it was an
undefined variable, the ldap_bind() will just perform an anonymous
bind and return true!


You have:
$upw = "pass";

but using $upd in ldap_bind ...

if(!$r=ldap_bind($ds, $un, $upd)){

unless it's a typo in your example that could explain it. ?

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



Re: [PHP] Is it better to return a multi-array, or an array of objects?

2006-03-03 Thread Murray @ PlanetThoughtful

On 4/03/2006 3:10 PM, Daevid Vincent wrote:

I'm building a fairly large project. I've been trying to follow best
practices, but I'm a bit worried about performance. Using PHP 5.1 and mySQL
5.0.

I have product and company classes.

So when a user does a search of the database, is it better/faster/etc. to
return just a two dimensional associative array to populate an HTML table of
the results like: product name, product id, price, company name, company
phone, etc. (assume I'm only showing some of the total number of fields).
  

[snip]

One observation: you shouldn't return all fields in a recordset unless 
you *need* all of the fields in a recordset.


The majority of the time, you should be explicitly stating which fields 
to retrieve in your SQL statement, as in:


SELECT field1, field2, field8 FROM mytable WHERE 

as opposed to:

SELECT * FROM mytable WHERE 

Some of the time, yes, that will mean you're explicitly typing out 7 
field names from a table that only has 8 field names, but getting out of 
the habit of using "*", particularly if you expect your application to 
work well under heavy loads, will save you resources, which will 
increase your app's overall performance.


It may be you're already doing this, but it wasn't clear from your post.

Much warmth,

planetthoughtful
---
"Lost in thought"
http://www.planetthoughtful.org

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



[PHP] Re: Is it better to return a multi-array, or an array of objects?

2006-03-03 Thread Manuel Lemos
Hello,

on 03/04/2006 02:10 AM Daevid Vincent said the following:
> Does it matter that I'm only showing say 10 fields of perhaps 50 or more
> possible ones (that the classes and database would hold)?
> 
> My gut feeling is to use an array as it seems less overhead and "faster".
> However the object versions seems to be more expandable and maintainable
> perhaps. Although a bit more work due to all the method calls to pull out
> the stuff to display in the HTML.

Obviously retrieving arrays with only the fields of the objects you need
is the fastest way.

-- 

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

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



Re: [PHP] Mysql Rows

2006-03-03 Thread Murray @ PlanetThoughtful

On 4/03/2006 2:49 PM, benifactor wrote:

thank you. the table does have and id feild that auto increments, however if
you delete a user there will be a gap between the users between which would
not be what is not acurate enough. thank you for you help. simple fix. i
should have caught it.
- Original Message - 
From: "Anthony Ettinger" <[EMAIL PROTECTED]>

To: "benifactor" <[EMAIL PROTECTED]>
Cc: "php" 
Sent: Friday, March 03, 2006 3:52 PM
Subject: Re: [PHP] Mysql Rows


define $1 = 0 outside your loop.

i'm curious why you are relying on row-order in the database?
Typically you'd have a PRIMARY KEY auto_increment for something like
this.

  


I have to agree with Anthony - why are you using row order to determine 
something relating to users? I couldn't follow your brief explanation 
above, and the fact that you're doing it sets off some soft alarm bells 
about the design of your application. Why is it important that there 
shouldn't be any 'gaps' between users? Because you want to know how many 
users there are? If so, simply do a SELECT COUNT(*) on the table 
whenever / wherever you need to know.


If you're using it for IDs for the users, it's generally a bad idea to 
reuse this type of information. If you have some other purpose, I'm 
extremely curious about what it might be.


Much warmth,

planetthoughtful
---
"Lost in thought"
http://www.planetthoughtful.org

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



Re: [PHP] Mysql Rows

2006-03-03 Thread Anthony Ettinger
On 3/3/06, Murray @ PlanetThoughtful <[EMAIL PROTECTED]> wrote:
> On 4/03/2006 2:49 PM, benifactor wrote:
> > thank you. the table does have and id feild that auto increments, however if
> > you delete a user there will be a gap between the users between which would
> > not be what is not acurate enough. thank you for you help. simple fix. i
> > should have caught it.
> > - Original Message -
> > From: "Anthony Ettinger" <[EMAIL PROTECTED]>
> > To: "benifactor" <[EMAIL PROTECTED]>
> > Cc: "php" 
> > Sent: Friday, March 03, 2006 3:52 PM
> > Subject: Re: [PHP] Mysql Rows
> >
> >
> > define $1 = 0 outside your loop.
> >
> > i'm curious why you are relying on row-order in the database?
> > Typically you'd have a PRIMARY KEY auto_increment for something like
> > this.
> >
> >
>
> I have to agree with Anthony - why are you using row order to determine
> something relating to users? I couldn't follow your brief explanation
> above, and the fact that you're doing it sets off some soft alarm bells
> about the design of your application. Why is it important that there
> shouldn't be any 'gaps' between users? Because you want to know how many
> users there are? If so, simply do a SELECT COUNT(*) on the table
> whenever / wherever you need to know.
>
> If you're using it for IDs for the users, it's generally a bad idea to
> reuse this type of information. If you have some other purpose, I'm
> extremely curious about what it might be.
>
> Much warmth,
>
> planetthoughtful
> ---
> "Lost in thought"
> http://www.planetthoughtful.org
>
>


What I was getting at is you get the unique id for the username (if
you allow username changes, then you want a unique key to do your
joins on from other tables).



--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

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



Re: [PHP] Coding Practice: Use global $var or pass in by refernce

2006-03-03 Thread Paul Scott
On Fri, 2006-03-03 at 16:19 -0500, tedd wrote:
> Perhaps I'm fortunate, but I usually find a way around using Globals. 
> And since I've been coding in PHP, I've never been forced to use them.
> 

Just my 2c...

In our framework, I use globals as well, although I do tend to agree
with Tedd regarding workarounds rather... :)

Something like so:

I create a global to hold the db object (in my case MDB2 or PEAR DB) and
then use a loadclass function to get the dbconfig from another module.
This creates a nice way to easily pick it up wherever its needed. I then
use the factory method to instantiate the db abstraction layer and pass
it, through my "engine class" to an "object class" where I further
abstract the db functions through a central db class. All of the modules
in the system that have database derived classes extend my dbTable
class, thereby keeping everything centralised.

In dbTable class, I evaluate if the db object exists, and if it *really*
doesn't, I create it through the engine. This makes for "lazy"
evaluation of the db object, so that it works kinda on demand, rather
than on every request.

Using this method, I can also use a global error callback method to
handle _all_ database errors gracefully, using PEAR_Error. I do think
that there may be a slight performance hit doing it this way, but in an
app with over 180 000 lines of code (so far) I find it works just
fine...

--Paul

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



RE: [PHP] Is it better to return a multi-array, or an array of objects?

2006-03-03 Thread Daevid Vincent
> SELECT field1, field2, field8 FROM mytable WHERE 
> 
> as opposed to:
> 
> SELECT * FROM mytable WHERE 
>
> It may be you're already doing this, but it wasn't clear from your post.

Yes, Murray, thank you, and I am already doing this. :)

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



Re: [PHP] Mysql Rows

2006-03-03 Thread Murray @ PlanetThoughtful



I have to agree with Anthony - why are you using row order to determine
something relating to users? I couldn't follow your brief explanation
above, and the fact that you're doing it sets off some soft alarm bells
about the design of your application. Why is it important that there
shouldn't be any 'gaps' between users? Because you want to know how many
users there are? If so, simply do a SELECT COUNT(*) on the table
whenever / wherever you need to know.

If you're using it for IDs for the users, it's generally a bad idea to
reuse this type of information. If you have some other purpose, I'm
extremely curious about what it might be.




What I was getting at is you get the unique id for the username (if
you allow username changes, then you want a unique key to do your
joins on from other tables).

  


Yep, that's one good reason among many for using unique ids. Thinking a 
little about the OP's question, I could understand row order being 
relevant in certain situations where you wanted to display something 
like, "You were the 432nd person to register at our site!", etc.


But, too often I've seen people new to database design not liking 'gaps' 
because 'user1' will have a unique id of '1', while 'user2' will have a 
unique id of '6' because the records associated with unique ids '2' 
through '5' were deleted during testing, and so on. So, they feel that 
'user2' should have a unique id of '2', ignoring the fact that that's 
not a unique id at all, if you had id '2' associated with another record 
at some point.


I'm not suggesting this is what the OP is doing, just that that's why I 
was curious about the purpose.


Much warmth,

planetthoughtful
---
"Lost in thought"
http://www.planetthoughtful.org

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



Re: [PHP] Mysql Rows

2006-03-03 Thread Anthony Ettinger
On 3/3/06, Murray @ PlanetThoughtful <[EMAIL PROTECTED]> wrote:
>
> >
> >> I have to agree with Anthony - why are you using row order to determine
> >> something relating to users? I couldn't follow your brief explanation
> >> above, and the fact that you're doing it sets off some soft alarm bells
> >> about the design of your application. Why is it important that there
> >> shouldn't be any 'gaps' between users? Because you want to know how
> many
> >> users there are? If so, simply do a SELECT COUNT(*) on the table
> >> whenever / wherever you need to know.
> >>
> >> If you're using it for IDs for the users, it's generally a bad idea to
> >> reuse this type of information. If you have some other purpose, I'm
> >> extremely curious about what it might be.
> >>
> >
> >
> > What I was getting at is you get the unique id for the username (if
> > you allow username changes, then you want a unique key to do your
> > joins on from other tables).
> >
> >
>
> Yep, that's one good reason among many for using unique ids. Thinking a
> little about the OP's question, I could understand row order being
> relevant in certain situations where you wanted to display something
> like, "You were the 432nd person to register at our site!", etc.



I'd do this with a timestamp, and then sorting by date and doing a count()
on the results. But then again that's just me. I remember the days where i'd
clear a database after testing to keep the auto_increment inline, but
eventually, you will get out of sync on that, so it's not a reliable way of
keeping a numerical sequence.



But, too often I've seen people new to database design not liking 'gaps'
> because 'user1' will have a unique id of '1', while 'user2' will have a
> unique id of '6' because the records associated with unique ids '2'
> through '5' were deleted during testing, and so on. So, they feel that
> 'user2' should have a unique id of '2', ignoring the fact that that's
> not a unique id at all, if you had id '2' associated with another record
> at some point.
>
> I'm not suggesting this is what the OP is doing, just that that's why I
> was curious about the purpose.
>
> Much warmth,
>
> planetthoughtful
> ---
> "Lost in thought"
> http://www.planetthoughtful.org
>
>


--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html


Re: [PHP] Mysql Rows

2006-03-03 Thread Murray @ PlanetThoughtful

On 4/03/2006 5:36 PM, Anthony Ettinger wrote:



Yep, that's one good reason among many for using unique ids.
Thinking a
little about the OP's question, I could understand row order being
relevant in certain situations where you wanted to display something
like, "You were the 432nd person to register at our site!", etc.



I'd do this with a timestamp, and then sorting by date and doing a 
count() on the results. But then again that's just me. I remember the 
days where i'd clear a database after testing to keep the 
auto_increment inline, but eventually, you will get out of sync on 
that, so it's not a reliable way of keeping a numerical sequence.


Right, or you could just as easily do the same sort and WHERE clause by 
your unique id, but even just doing a count, you're interested in the 
fact that the record is at position  in that recordset, so 
'row order' is relevant and, in that context, meaningful.


Much warmth,

planetthoughtful
---
"Lost in thought"
http://www.planetthoughtful.org

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