php-general Digest 21 Jan 2009 09:08:48 -0000 Issue 5914

2009-01-21 Thread php-general-digest-help

php-general Digest 21 Jan 2009 09:08:48 - Issue 5914

Topics (messages 286889 through 286906):

Re: Client/Server Printing
286889 by: Frank Stanovcak
286901 by: Tony Marston

Re: Installation problems on Vista
286890 by: lucson pierre-charles
286891 by: Nathan Rixham
286892 by: lucson pierre-charles
286894 by: lucson pierre-charles
286895 by: Shawn McKenzie
286896 by: Nathan Rixham
286897 by: Shawn McKenzie
286898 by: lucson pierre-charles
286899 by: Shawn McKenzie

Curl fiel Upload
286893 by: Matthias Laug
286900 by: Manuel Lemos

Please explain: index.php/index/index
286902 by: leledumbo
286903 by: Carlos Medina
286904 by: leledumbo
286905 by: Török Alpár
286906 by: leledumbo

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---
Paul M Foster pa...@quillandmouse.com wrote in message
news:20090120151606.gu18...@quillandmouse.com...
 I'd like a side check on what I'm doing to print on our internal
 network.

 We have an internal server/site which uses PHP code I've written to
 run the business-- invoicing, A/P, inventory, etc. Some things, like
 invoices and reports, need to be printed. Now remember, the code is on
 the server, and we access it from our client machines on our desks. When
 we print, we do so to our local printers, attached to the client
 machines.

 So the best way I could think of to making printing work was to generate
 PDFs of whatever needs to be printed, dump the PDF on the server, and
 provide a link to the PDF on the web page. The user clicks on the
 generated PDF, and his/her browser opens up Acrobat or xpdf, and prints
 from that application to their local machine.

 Is that a reasonable way to implement this? Any better ideas?

 Paul

 -- 
 Paul M. Foster

I'm using fpdf to generate a pdf that is
displayed in a seperate window for review prior to printing...sort of like a
print preveiw.  If you can set the webserver to process .pdf files through
php it will display in the adobe reader plug in and all the client has to do
is hit print.

www. fpdf .com

Frank







---End Message---
---BeginMessage---

Paul M Foster pa...@quillandmouse.com wrote in message 
news:20090120151606.gu18...@quillandmouse.com...
 I'd like a side check on what I'm doing to print on our internal
 network.

 We have an internal server/site which uses PHP code I've written to
 run the business-- invoicing, A/P, inventory, etc. Some things, like
 invoices and reports, need to be printed. Now remember, the code is on
 the server, and we access it from our client machines on our desks. When
 we print, we do so to our local printers, attached to the client
 machines.

 So the best way I could think of to making printing work was to generate
 PDFs of whatever needs to be printed, dump the PDF on the server, and
 provide a link to the PDF on the web page. The user clicks on the
 generated PDF, and his/her browser opens up Acrobat or xpdf, and prints
 from that application to their local machine.

 Is that a reasonable way to implement this? Any better ideas?

I have built an application similar to yours, and I have solved the printing 
problem by using software from the following two companies: 
http://www.nicelabel.com and http://www.namtuk.com/autoprintemail.aspx

Basically the user runs a web page which generates the required report, in 
either XML or PDF format (I believe others are available) and sends an email 
which identifies a particular client printer. At the client end, with any 
number of PCs and printers, there is a piece of software running which looks 
for these emails, and when one is received it sends the print to the 
designated printer. Each report can be tailored to output to any printer, 
including a specific printer for each user. This means that the user does 
not see the generated report in his web browser and then have to press the 
PRINT key and choose the printer before it gets printed. He simply presses a 
Generate Report button, and within a few seconds it is sent to the 
printer.

It's not free, but it's worth the money (IMHO).

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

 Paul

 -- 
 Paul M. Foster 


---End Message---
---BeginMessage---

Dear Nathan,
 The short_tags is sure off but when I changed the scripts, 
they're still being output to the browser. 
 
These are the lines I added to the modules section:
#LoadModule php5_module c:/php5/php5apache2.dll#AddType application/x-httpd-php 
.php#PHPIniDir c:/php5
 
I added these lines to the DirectoryIndex:
DirectoryIndex index.html index.html.var 

[PHP] Please explain: index.php/index/index

2009-01-21 Thread leledumbo

I don't understand it. index.php should be a file and indeed it's a file, so
what does /index/index after it mean? There's no index directory under
directory where index.php resides.
-- 
View this message in context: 
http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21578728.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] Please explain: index.php/index/index

2009-01-21 Thread Carlos Medina

leledumbo schrieb:

I don't understand it. index.php should be a file and indeed it's a file, so
what does /index/index after it mean? There's no index directory under
directory where index.php resides.

Hi Leledumbo,
what are you talking about? I think you are confused on this:

http://www.domain.com/index

or this

http://www.domain.com/index.php

Yes this is a Front Controller situation (Pattern). Please show the Zend 
Framework or other Frameworks that implements this Pattern (maybe the 
Command Pattern too ).


Regards

Carlos

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



Re: [PHP] Please explain: index.php/index/index

2009-01-21 Thread leledumbo



Carlos Medina-2 wrote:
 
 this is a Front Controller situation (Pattern)
 
Could you explain more on that? I've never seen anything like this in any
tutorial I've found on the net. I'm using kohana framework. So, if I have
index.php/index/index where does it actually go?
-- 
View this message in context: 
http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579231.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] Please explain: index.php/index/index

2009-01-21 Thread Török Alpár
2009/1/21 leledumbo leledumbo_c...@yahoo.co.id




 Carlos Medina-2 wrote:
 
  this is a Front Controller situation (Pattern)
 
 Could you explain more on that? I've never seen anything like this in any
 tutorial I've found on the net. I'm using Kohana framework. So, if I have
 index.php/index/index where does it actually go?

  it goes to index.php , apache disregards what's after index.php Kohana the
reads that string, and loads the appropriate Controller / method. You can
hide the index.php from your users via apaches mod_rewrite. Refere to the
Kohana or Codeigniter doccumentation


 --
 View this message in context:
 http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579231.html
 Sent from the PHP - General mailing list archive at Nabble.com.


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




-- 
Torok, Alpar Istvan


Re: [PHP] Please explain: index.php/index/index

2009-01-21 Thread leledumbo

Is this web server specific? I can't get it to run under Microsoft IIS, but
it works flawlessly in Apache.
-- 
View this message in context: 
http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579384.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



Re: [PHP] Please explain: index.php/index/index

2009-01-21 Thread Török Alpár
Never used IIS, but under the circumstances, i think you got your answer. I
remember that codeigniter support many ways of getting that string, i
believe kohana does the same. You probably need to change some
configuration options for IIS

2009/1/21 leledumbo leledumbo_c...@yahoo.co.id


 Is this web server specific? I can't get it to run under Microsoft IIS, but
 it works flawlessly in Apache.
 --
 View this message in context:
 http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21579384.html
 Sent from the PHP - General mailing list archive at Nabble.com.


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




-- 
Torok, Alpar Istvan


Re: [PHP] Please explain: index.php/index/index

2009-01-21 Thread clive

leledumbo wrote:

Is this web server specific? I can't get it to run under Microsoft IIS, but
it works flawlessly in Apache.
  
IIS 6 and below dont have an option like mod_rewrite, apparently IIS 7 
does, I haven't tried it yet. There are a number of 3rd party apps that 
can add this functionality to IIS 6, some are free and some paid for, Im 
currently using Isap/rewrite from helicontech which works for my needs ( 
zend framework).


Clive


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



Re: [PHP] Re: Client/Server Printing

2009-01-21 Thread Bastien Koert
On Tue, Jan 20, 2009 at 8:00 PM, Tony Marston t...@marston-home.demon.co.uk
 wrote:


 Paul M Foster pa...@quillandmouse.com wrote in message
 news:20090120151606.gu18...@quillandmouse.com...
  I'd like a side check on what I'm doing to print on our internal
  network.
 
  We have an internal server/site which uses PHP code I've written to
  run the business-- invoicing, A/P, inventory, etc. Some things, like
  invoices and reports, need to be printed. Now remember, the code is on
  the server, and we access it from our client machines on our desks. When
  we print, we do so to our local printers, attached to the client
  machines.
 
  So the best way I could think of to making printing work was to generate
  PDFs of whatever needs to be printed, dump the PDF on the server, and
  provide a link to the PDF on the web page. The user clicks on the
  generated PDF, and his/her browser opens up Acrobat or xpdf, and prints
  from that application to their local machine.
 
  Is that a reasonable way to implement this? Any better ideas?

 I have built an application similar to yours, and I have solved the
 printing
 problem by using software from the following two companies:
 http://www.nicelabel.com and http://www.namtuk.com/autoprintemail.aspx

 Basically the user runs a web page which generates the required report, in
 either XML or PDF format (I believe others are available) and sends an
 email
 which identifies a particular client printer. At the client end, with any
 number of PCs and printers, there is a piece of software running which
 looks
 for these emails, and when one is received it sends the print to the
 designated printer. Each report can be tailored to output to any printer,
 including a specific printer for each user. This means that the user does
 not see the generated report in his web browser and then have to press the
 PRINT key and choose the printer before it gets printed. He simply presses
 a
 Generate Report button, and within a few seconds it is sent to the
 printer.

 It's not free, but it's worth the money (IMHO).

 --
 Tony Marston
 http://www.tonymarston.net
 http://www.radicore.org

  Paul
 
  --
  Paul M. Foster



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


I still like dompdf from
http://www.digitaljunkies.cahttp://www.digitaljunkies.com

-- 

Bastien

Cat, the other other white meat


[PHP] how to simplify my code - I will have tooo many lines - please help

2009-01-21 Thread kabucek1

hi all,

I have form in which people renew their agreements online.
they can renew up to 5 agreements.
I need to check if the expiration date is older than today, late fee will be
added.
if exp. date is equal or newer - no late fee.
I have something like this so far and I can go further with this
but my question is, if there is a way to simplify this code a little bit,
or to make it shorter?


 $Today=date('m/d/y');

 if  ($selectedProdCode=agreem and $errorArray['agr1expdate']  $Today)
  {
$selectedProdCode=// code with 1 agr and late fee
}
   else {//1 agr
  if  ( $selectedProdCode=agreem and
$errorArray['agr1expdate']  $Today)
{
  $selectedProdCode=// code with 1 agr and no late fee
}
 else
  {
if ($selectedProdCode=agreem and
$errorArray['agr1expdate']  $Today)
{
   $selectedProdCode=// code with 1 agr and late fee
}
   }
 else
  {
if ($selectedProdCode=agreem and
$errorArray['agr1expdate'] == $Today)
{
   $selectedProdCode=// code with 1 agr and no late
fee
}
   }
   
  
/--
   //2 agr
 else
  {
if ( $selectedProdCode=agreem2 and
$errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate'] ==
$Today )
{
   $selectedProdCode=// code with 2 certs and no
late fee
}
   }

   else
  {
if ($selectedProdCode=agreem2 and
$errorArray['agr1expdate']  $Today and $errorArray['agr2expdate']  $Today
{
   $selectedProdCode=// code with 2 agr and no late
fee
}
   }
   
   else
  {
if ($selectedProdCode=agreem2 and
$errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate']  $Today
{
   $selectedProdCode=// code with 2 agr and no late
fee
}
   }
   
   else
  {
if ($selectedProdCode=agreemn2 and
$errorArray['agr1expdate']  $Today and $errorArray['agr2expdate'] == $Today
{
   $selectedProdCode=// code with 2 certs and no
late fee
}
   }
   
   else
  {
if ($selectedProdCode=agreem2 and
$errorArray['agr1expdate']  $Today and $errorArray['agr2expdate'] == $Today
{
   $selectedProdCode=// code with 2 certs and plus
1x late fee
}
   }

   else
  {
if ($selectedProdCode=agreem2 and
$errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate']  $Today
{
   $selectedProdCode=// code with 2 agr and plus 1x
late fee
}
   }
   
   else
  {
if ($selectedProdCode=agreem2 and
$errorArray['agr1expdate']  $Today and $errorArray['agr2expdate']  $Today
{
   $selectedProdCode=// code with 2 certs and plus
1x late fee
}
   }
   
   else
  {
if ($selectedProdCode=agreem2 and
$errorArray['agr1expdate']  $Today and $errorArray['agr2expdate']  $Today
{
   $selectedProdCode=// code with 2 agr and plus 1x
late fee
}
   }
   
 



Thanks  
   
-- 
View this message in context: 
http://www.nabble.com/how-to-simplify-my-code---I-will-have-tooo-many-lines---please-help-tp21585387p21585387.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



RE: [PHP] Please explain: index.php/index/index

2009-01-21 Thread Boyd, Todd M.
 -Original Message-
 From: clive [mailto:clive_li...@immigrationunit.com]
 Sent: Wednesday, January 21, 2009 3:36 AM
 To: leledumbo
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Please explain: index.php/index/index
 
 leledumbo wrote:
  Is this web server specific? I can't get it to run under Microsoft
 IIS, but
  it works flawlessly in Apache.
 
 IIS 6 and below dont have an option like mod_rewrite, apparently IIS 7
 does, I haven't tried it yet. There are a number of 3rd party apps
that
 can add this functionality to IIS 6, some are free and some paid for,
 Im
 currently using Isap/rewrite from helicontech which works for my needs
 (
 zend framework).

IIRF - Ionics ISAPI Rewrite Filter [1] is totally free... and it
supports the use of Regular Expressions [2] in your rewrite rules. If
you're going to use any sort of MVC-based URLs in IIS, this library is a
must-have.

1. http://www.codeplex.com/IIRF
2. http://www.regular-expressions.info

HTH,


// Todd

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



Re: [PHP] I can't get help from the binary administrator

2009-01-21 Thread Eduardo Varela
Thanks, Daniel !! It worked.
Next week I will have finished to read posts and willl begin a new task:
Break the digest posts into individual messages, off-line, of course. I will
try to do it  with UltraEdit macros and then with PHP.

Should I have any problem, I will share it.

Thanks, again,
Eduardo
- Original Message -
From: Daniel Brown danbr...@php.net
To: Eduardo Varela vare...@gmail.com
Cc: php-general@lists.php.net
Sent: Thursday, January 15, 2009 7:17 PM
Subject: Re: [PHP] I can't get help from the binary administrator


 On Thu, Jan 15, 2009 at 16:35, Eduardo Varela vare...@gmail.com wrote:
 
  Does anyone know
  address
  subject
  text
  for getting a digest instead of the individual mails?

 You will have to first unsubscribe from the list, then subscribe
 to digest format at http://php.net/mailinglists

 If you have any problem in the process, let me know and I will be
 happy to help get your subscription switched over.

 Thanks, Eduardo.

 --
 /Daniel P. Brown
 daniel.br...@parasane.net || danbr...@php.net
 http://www.parasane.net/ || http://www.pilotpig.net/
 Unadvertised dedicated server deals, too low to print - email me to find
out!



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



Re: [PHP] how to simplify my code - I will have tooo many lines -please help

2009-01-21 Thread Shawn McKenzie
kabucek1 wrote:
 hi all,
 
 I have form in which people renew their agreements online.
 they can renew up to 5 agreements.
 I need to check if the expiration date is older than today, late fee will be
 added.
 if exp. date is equal or newer - no late fee.
 I have something like this so far and I can go further with this
 but my question is, if there is a way to simplify this code a little bit,
 or to make it shorter?
 
 
  $Today=date('m/d/y');
 
  if  ($selectedProdCode=agreem and $errorArray['agr1expdate']  $Today)
   {
 $selectedProdCode=// code with 1 agr and late fee
 }
else {//1 agr
   if  ( $selectedProdCode=agreem and
 $errorArray['agr1expdate']  $Today)
 {
   $selectedProdCode=// code with 1 agr and no late fee
 }
  else
   {
 if ($selectedProdCode=agreem and
 $errorArray['agr1expdate']  $Today)
 {
$selectedProdCode=// code with 1 agr and late fee
 }
}
  else
   {
 if ($selectedProdCode=agreem and
 $errorArray['agr1expdate'] == $Today)
 {
$selectedProdCode=// code with 1 agr and no late
 fee
 }
}

   
 /--
//2 agr
  else
   {
 if ( $selectedProdCode=agreem2 and
 $errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate'] ==
 $Today )
 {
$selectedProdCode=// code with 2 certs and no
 late fee
 }
}
 
else
   {
 if ($selectedProdCode=agreem2 and
 $errorArray['agr1expdate']  $Today and $errorArray['agr2expdate']  $Today
 {
$selectedProdCode=// code with 2 agr and no late
 fee
 }
}

else
   {
 if ($selectedProdCode=agreem2 and
 $errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate']  $Today
 {
$selectedProdCode=// code with 2 agr and no late
 fee
 }
}

else
   {
 if ($selectedProdCode=agreemn2 and
 $errorArray['agr1expdate']  $Today and $errorArray['agr2expdate'] == $Today
 {
$selectedProdCode=// code with 2 certs and no
 late fee
 }
}

else
   {
 if ($selectedProdCode=agreem2 and
 $errorArray['agr1expdate']  $Today and $errorArray['agr2expdate'] == $Today
 {
$selectedProdCode=// code with 2 certs and plus
 1x late fee
 }
}
 
else
   {
 if ($selectedProdCode=agreem2 and
 $errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate']  $Today
 {
$selectedProdCode=// code with 2 agr and plus 1x
 late fee
 }
}

else
   {
 if ($selectedProdCode=agreem2 and
 $errorArray['agr1expdate']  $Today and $errorArray['agr2expdate']  $Today
 {
$selectedProdCode=// code with 2 certs and plus
 1x late fee
 }
}

else
   {
 if ($selectedProdCode=agreem2 and
 $errorArray['agr1expdate']  $Today and $errorArray['agr2expdate']  $Today
 {
$selectedProdCode=// code with 2 agr and plus 1x
 late fee
 }
}

  
 
 
 
 Thanks  

Wow!  Yes, there are a lot of ways to do it.  This is a quick stab (not
tested):

$Today = date('m/d/y');

if ( $selectedProdCode=agreem  $errorArray['agr1expdate']  $Today)
{
$selectedProdCode= //agreement cost + late fee
} else {
$selectedProdCode= //agreement cost
}
if ( $selectedProdCode=agreem2  $errorArray['agr1expdate'] = $Today
 $errorArray['agr2expdate'] = $Today )
{   
$selectedProdCode= 

[PHP] Re: Curl fiel Upload

2009-01-21 Thread Matthias Laug
thanks!

2009/1/21 Manuel Lemos mle...@acm.org

 Hello,

 on 01/20/2009 09:10 PM Matthias Laug said the following:
  I've got a problem using curl to upload a file. I want to send it to a
 form
  written with the Django Framework.
 
  Post Request are processed correctly, with one anomaly.
  This piece of code works fine
 
  curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($data));
 
  But if i provide only an array no data is send to the form
 
  curl_setopt($process, CURLOPT_POSTFIELDS, $data);
 
  I have read somewhere that curl sends formdata with
 enctype=form/mulitpart
  only if I provide an array not a string.
 
  If I add @filename to the $data variable (string or array) it does not
  send the file to the form.
 
  Each example I have found in the internet so far did not work.

 I do not use the Curl functions directly. When possible I use fsockopen
 as alternative and use this HTTP client class to submit any kind of HTTP
 requests. Take a look at the test_http_post.php to see how simple is to
 submit form with one or more file uploads.

 http://www.phpclasses.org/httpclient



 --

 Regards,
 Manuel Lemos

 Find and post PHP jobs
 http://www.phpclasses.org/jobs/

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




-- 
Matthias Laug
Schillerstr. 36
10627 Berlin
http://www.mconcepts-online.com/


[PHP] MySQL class. Thoughts?

2009-01-21 Thread Jay Moore
This is a MySQL class I use and I wanted to get everyone's thoughts on 
how/if I can improve it.  This is for MySQL only.  I don't need to make 
it compatible with other databases.  I'm curious what you all think.


Thanks,
Jay

Class:
--
?php

// Standard MySQL class
class do_mysql
{   
// Constructor
function __construct()
{
$this-do_mysql();
}

// Destructor
function __destruct()
{
//$this-close();
}

function do_mysql()
{
$this-login = '';
$this-pass = '';

		$this-link = @mysql_connect('localhost', $this-login, $this-pass) 
or die('Could not connect to the database.');

} // End do_mysql

// Functions
function close()
{
if ($this-link)
{
mysql_close($this-link);
unset($this-link);
}
} // End close

function fetch_array()
{
return mysql_fetch_array($this-result);
} // End fetch_array

function last_id()
{
return mysql_insert_id($this-link);
} // End last_id

function num_rows()
{
return mysql_num_rows($this-result);
} // End num_rows

function process($database = '')
{
if (is_null($this-query))
{
die('Error:  Query string empty.  Cannot proceed.');
}

		$this-db = @mysql_select_db($database, $this-link) or die(Database 
Error:  Couldn't select $database br / . mysql_error());
		$this-result = @mysql_query($this-query, $this-link) or 
die('Database Error:  Couldn\'t query. br /' . mysql_error() . br 
/br / $this-query);

} // End process

function sanitize($ref)
{
$ref = mysql_real_escape_string($ref);
} // End sanitize

} // End do_mysql

?


Sample usage:
$value = 'value';
$sql = new do_mysql();
$sql-sanitize($value);
$sql-query = SELECT * FROM `wherever` WHERE `field` = '$value';
$sql-process('dbname');
$sql-close();

if ($sql-num_rows())
{
while ($row = $sql-fetch_array())
{
do stuff;
}
}

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Edmund Hertle
2009/1/21 Jay Moore jaymo...@accu-com.com

 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make it
 compatible with other databases.  I'm curious what you all think.

 Thanks,
 Jay


Hey,
1. You know the mysqli-Class?
2. If yes, than I don't get it in which way this will improve mysql handling

 -eddy


Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Kyle Terry
On Wed, Jan 21, 2009 at 9:45 AM, Edmund Hertle
edmund.her...@student.kit.edu wrote:
 2009/1/21 Jay Moore jaymo...@accu-com.com

 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make it
 compatible with other databases.  I'm curious what you all think.

 Thanks,
 Jay


 Hey,
 1. You know the mysqli-Class?
 2. If yes, than I don't get it in which way this will improve mysql handling

  -eddy


MySQLi actually stands for MySQL Improved. Problem solved.

-- 
Kyle Terry | www.kyleterry.com

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 12:45 PM, Edmund Hertle
edmund.her...@student.kit.edu wrote:
 2009/1/21 Jay Moore jaymo...@accu-com.com

 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make it
 compatible with other databases.  I'm curious what you all think.

 Thanks,
 Jay


 Hey,
 1. You know the mysqli-Class?
 2. If yes, than I don't get it in which way this will improve mysql handling

  -eddy


Yea if you're only targeting 1 db, then why not use that class?  At
least then there's the php manual to figure out what something does.

mysql_real_escape_string should use $this-link to properly escape
based on charset, not server default.  I'd also call it escape.

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



[PHP] Redirecting from unreachable page on website

2009-01-21 Thread Dušan Novaković
Hi,

Is there some elegant solution how to redirect if someone try to open
some non existing page (e.g www.domain.com/nonexistingpage.php) to
main page www.domain.com on website?

thnx, Dusan

-- 
made by Dusan

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



Re: [PHP] Redirecting from unreachable page on website

2009-01-21 Thread Kyle Terry
On Wed, Jan 21, 2009 at 10:12 AM, Dušan Novaković ndu...@gmail.com wrote:
 Hi,

 Is there some elegant solution how to redirect if someone try to open
 some non existing page (e.g www.domain.com/nonexistingpage.php) to
 main page www.domain.com on website?

 thnx, Dusan

 --
 made by Dusan

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



Google for apache 404 redirect and read around a bit. Checkout the
documentation on apache.org as well.

-- 
Kyle Terry | www.kyleterry.com

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



Re: [PHP] Redirecting from unreachable page on website

2009-01-21 Thread Kyle Terry
2009/1/21 Kyle Terry k...@kyleterry.com:
 On Wed, Jan 21, 2009 at 10:12 AM, Dušan Novaković ndu...@gmail.com wrote:
 Hi,

 Is there some elegant solution how to redirect if someone try to open
 some non existing page (e.g www.domain.com/nonexistingpage.php) to
 main page www.domain.com on website?

 thnx, Dusan

 --
 made by Dusan

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



 Google for apache 404 redirect and read around a bit. Checkout the
 documentation on apache.org as well.

 --
 Kyle Terry | www.kyleterry.com


That was assuming you are using apache by the way. What web server are
you using?

-- 
Kyle Terry | www.kyleterry.com

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



Re: [PHP] how to simplify my code - I will have tooo many lines -pleasehelp

2009-01-21 Thread Shawn McKenzie
Shawn McKenzie wrote:
 Wow!  Yes, there are a lot of ways to do it.  This is a quick stab (not
 tested):
 
 $Today = date('m/d/y');
 
 if ( $selectedProdCode == agreem  $errorArray['agr1expdate']  $Today)
 {
   $selectedProdCode= //agreement cost + late fee
 } else {
   $selectedProdCode= //agreement cost
 }
 if ( $selectedProdCode == agreem2  $errorArray['agr1expdate'] = $Today
  $errorArray['agr2expdate'] = $Today )
 { 
   $selectedProdCode= //agreement cost * 2
 }
 elseif ( $selectedProdCode == agreem2  ($errorArray['agr1expdate'] 
 $Today || $errorArray['agr2expdate']  $Today) )
 { 
   if ( $errorArray['agr1expdate']  $Today  $errorArray['agr2expdate']
  $Today )
   {
   $selectedProdCode= //(agreement cost * 2) + (late fee *2)
   } else {
   $selectedProdCode= //(agreement cost * 2) + late fee
   }   
 }
 
Here's another stab (not tested).  Also, in my previous post I just
copied your code, there should be == instead of = in the if expressions.

$Today = date('m/d/y');
$Agreements = 0;
$lateFees = 0;

if ( $selectedProdCode == agreem )
{
$Agreements = 1;
}
elseif ( $selectedProdCode == agreem2 )
{
$Agreements = 2;

if ( $errorArray['agr2expdate']  $Today )
{
$lateFees++;
}
}
if ( $errorArray['agr1expdate']  $Today )
{
$lateFees++;
}
$selectedProdCode= //(agreement cost * $Agreements) + (late fee * $lateFees)

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] About printing functions

2009-01-21 Thread Thodoris

Hi gang,
   Lets say that you have a function that prints something to the 
output simply like this:


function print_str() {
   print blah blah blah;
}

I was wondering if there is a way to use this output and store it in a 
var or something without changing the function itself?

And store the blah blah blah somewhere for later use?

I can think of many reasons that someone could use this.

--
Thodoris


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



Re: [PHP] About printing functions

2009-01-21 Thread Jason Pruim


On Jan 21, 2009, at 1:33 PM, Thodoris wrote:


Hi gang,
   Lets say that you have a function that prints something to the  
output simply like this:


function print_str() {
   print blah blah blah;
}

I was wondering if there is a way to use this output and store it  
in a var or something without changing the function itself?

And store the blah blah blah somewhere for later use?

I can think of many reasons that someone could use this.



I know you said without changing the function... but is there any  
reason that you can't simply add this:


?PHP
function print_str() {
$str = blah blah blah;
print $str;
}
?

Totally untested and just trying to understand why :)


--
Jason Pruim
japr...@raoset.com
616.399.2355





Re: [PHP] Redirecting from unreachable page on website

2009-01-21 Thread Dušan Novaković
apache :-)

2009/1/21 Kyle Terry k...@kyleterry.com:
 2009/1/21 Kyle Terry k...@kyleterry.com:
 On Wed, Jan 21, 2009 at 10:12 AM, Dušan Novaković ndu...@gmail.com wrote:
 Hi,

 Is there some elegant solution how to redirect if someone try to open
 some non existing page (e.g www.domain.com/nonexistingpage.php) to
 main page www.domain.com on website?

 thnx, Dusan

 --
 made by Dusan

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



 Google for apache 404 redirect and read around a bit. Checkout the
 documentation on apache.org as well.

 --
 Kyle Terry | www.kyleterry.com


 That was assuming you are using apache by the way. What web server are
 you using?

 --
 Kyle Terry | www.kyleterry.com




-- 
made by Dusan

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



Re: [PHP] Redirecting from unreachable page on website

2009-01-21 Thread Kyle Terry
On Wed, Jan 21, 2009 at 10:40 AM, Dušan Novaković ndu...@gmail.com wrote:
 apache :-)

 2009/1/21 Kyle Terry k...@kyleterry.com:
 2009/1/21 Kyle Terry k...@kyleterry.com:
 On Wed, Jan 21, 2009 at 10:12 AM, Dušan Novaković ndu...@gmail.com wrote:
 Hi,

 Is there some elegant solution how to redirect if someone try to open
 some non existing page (e.g www.domain.com/nonexistingpage.php) to
 main page www.domain.com on website?

 thnx, Dusan

 --
 made by Dusan

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



 Google for apache 404 redirect and read around a bit. Checkout the
 documentation on apache.org as well.

 --
 Kyle Terry | www.kyleterry.com


 That was assuming you are using apache by the way. What web server are
 you using?

 --
 Kyle Terry | www.kyleterry.com




 --
 made by Dusan

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



This will be your best friend then.
http://httpd.apache.org/docs/2.2/custom-error.html

-- 
Kyle Terry | www.kyleterry.com

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



Re: [PHP] Redirecting from unreachable page on website

2009-01-21 Thread Per Jessen
Dušan Novaković wrote:

 Hi,
 
 Is there some elegant solution how to redirect if someone try to open
 some non existing page (e.g www.domain.com/nonexistingpage.php) to
 main page www.domain.com on website?
 

See Apache ErrorDocument directive.


/Per Jessen, Zürich


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



Re: [PHP] About printing functions

2009-01-21 Thread Edmund Hertle
2009/1/21 Jason Pruim japr...@raoset.com


 On Jan 21, 2009, at 1:33 PM, Thodoris wrote:

  Hi gang,
   Lets say that you have a function that prints something to the output
 simply like this:

 function print_str() {
   print blah blah blah;
 }

 I was wondering if there is a way to use this output and store it in a var
 or something without changing the function itself?
 And store the blah blah blah somewhere for later use?

 I can think of many reasons that someone could use this.


 I know you said without changing the function... but is there any reason
 that you can't simply add this:

 ?PHP
 function print_str() {
$str = blah blah blah;
print $str;
 }
 ?

well, I think this will not work because $str is only valid in the function
(local var!)


[PHP] Suggested diagramming package for php application

2009-01-21 Thread Anne Watelet
Hi - we currently use visio for creating basic block diagrams and save these 
as images to our web site so others can view them. What we really would like 
to do is to have our php application be able to display the diagram and then 
upon clicking an edit button, allow the user to edit the diagram directly. 
We are currently using php 5 and postgresql 8.2 on an Ubuntu server. I was 
wondering if anyone had any suggestions on an open source package that would 
allow us to do this functionality? Thank you in advance for any help or 
insight! 



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



Re: [PHP] About printing functions

2009-01-21 Thread Thodoris




On Jan 21, 2009, at 1:33 PM, Thodoris wrote:


Hi gang,
   Lets say that you have a function that prints something to the 
output simply like this:


function print_str() {
   print blah blah blah;
}

I was wondering if there is a way to use this output and store it in 
a var or something without changing the function itself?

And store the blah blah blah somewhere for later use?

I can think of many reasons that someone could use this.



I know you said without changing the function... but is there any 
reason that you can't simply add this:


?PHP
function print_str() {
$str = blah blah blah;
print $str;
}
?

Totally untested and just trying to understand why :)


--
Jason Pruim
japr...@raoset.com
616.399.2355






Well Jason my point is theoretical. Lets just say that this function 
doesn't just print blah blah blah but like tones of html that you may 
like to reuse...


Well you could always change it to this:

function print_str() {
   $str = blah blah blah;
   return $str;
}

and use the output you got from the function whenever you like (print 
it, make it a toast, cook it with bees etc).


But the question still remains: Is there a way to do this?

--
Thodoris


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



Re: [PHP] About printing functions

2009-01-21 Thread Török Alpár
you can use Output Buffering :

?php
   ob_start();
  badFunctionThatSpitsInsteadOfReturning();
   $sReturned = ob_get_contents();
  ob_end_clean();
?

2009/1/21 Edmund Hertle edmund.her...@student.kit.edu

 2009/1/21 Jason Pruim japr...@raoset.com

 
  On Jan 21, 2009, at 1:33 PM, Thodoris wrote:
 
   Hi gang,
Lets say that you have a function that prints something to the output
  simply like this:
 
  function print_str() {
print blah blah blah;
  }
 
  I was wondering if there is a way to use this output and store it in a
 var
  or something without changing the function itself?
  And store the blah blah blah somewhere for later use?
 
  I can think of many reasons that someone could use this.
 
 
  I know you said without changing the function... but is there any reason
  that you can't simply add this:
 
  ?PHP
  function print_str() {
 $str = blah blah blah;
 print $str;
  }
  ?

 well, I think this will not work because $str is only valid in the function
 (local var!)




-- 
Torok, Alpar Istvan


Re: [PHP] About printing functions

2009-01-21 Thread Edmund Hertle
2009/1/21 Thodoris t...@kinetix.gr



 On Jan 21, 2009, at 1:33 PM, Thodoris wrote:

  Hi gang,
   Lets say that you have a function that prints something to the output
 simply like this:

 function print_str() {
   print blah blah blah;
 }

 I was wondering if there is a way to use this output and store it in a
 var or something without changing the function itself?
 And store the blah blah blah somewhere for later use?

 I can think of many reasons that someone could use this.


 I know you said without changing the function... but is there any reason
 that you can't simply add this:

 ?PHP
 function print_str() {
$str = blah blah blah;
print $str;
 }
 ?

 Totally untested and just trying to understand why :)


 --
 Jason Pruim
 japr...@raoset.com
 616.399.2355





 Well Jason my point is theoretical. Lets just say that this function
 doesn't just print blah blah blah but like tones of html that you may like
 to reuse...


 Well you could always change it to this:

 function print_str() {
   $str = blah blah blah;
   return $str;
 }

 and use the output you got from the function whenever you like (print it,
 make it a toast, cook it with bees etc).

 But the question still remains: Is there a way to do this?


 --
 Thodoris


IMO it is always better to return strings than directly printing. there
would be no problem even if it would contain tones of html...

but what comes in my mind is output_buffering...
see: http://de3.php.net/manual/en/book.outcontrol.php

-eddy


Re: [PHP] About printing functions

2009-01-21 Thread Thodoris



you can use Output Buffering :

?php
   ob_start();
  badFunctionThatSpitsInsteadOfReturning();
   $sReturned = ob_get_contents();
  ob_end_clean();
?


  


That's a good though thanks. Although I was aware of output buffering I 
used to ignore that ob_end_clean actually exists...


--
Thodoris


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



[PHP] Military - Standard times

2009-01-21 Thread tedd

Hi gang:

What's the slickest way to go from standard to military times and back again?

Such as:

0800 - 8:00am
8:00am - 0800

-- or --

1600 - 4:00pm
4:00pm - 1600

I use the following functions, but is there anything better?

function standardToMilitary($t)
   {
   $t = strftime('%R', strtotime($t));
   return $t;
   }

function militaryToStandard($t)
   {
   $t = strftime('%r', strtotime($t));
   return $t;
   }

Thanks,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Paul M Foster
On Wed, Jan 21, 2009 at 11:37:07AM -0600, Jay Moore wrote:

 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make
 it compatible with other databases.  I'm curious what you all think.

 Thanks,
 Jay

 Class:
 --
 ?php

 // Standard MySQL class
 class do_mysql
 {
   // Constructor
   function __construct()
   {
   $this-do_mysql();
   }

   // Destructor
   function __destruct()
   {
   //$this-close();
   }

   function do_mysql()
   {
   $this-login = '';
   $this-pass = '';

   $this-link = @mysql_connect('localhost', $this-login,
   $this-pass)
 or die('Could not connect to the database.');
   } // End do_mysql

   // Functions
   function close()
   {
   if ($this-link)
   {
   mysql_close($this-link);
   unset($this-link);
   }
   } // End close

   function fetch_array()
   {
   return mysql_fetch_array($this-result);
   } // End fetch_array

   function last_id()
   {
   return mysql_insert_id($this-link);
   } // End last_id

   function num_rows()
   {
   return mysql_num_rows($this-result);
   } // End num_rows

   function process($database = '')
   {
   if (is_null($this-query))
   {
   die('Error:  Query string empty.  Cannot proceed.');
   }

   $this-db = @mysql_select_db($database, $this-link)
   or die(Database
 Error:Couldn't select $database br / . mysql_error());
   $this-result = @mysql_query($this-query, $this-link) or
 die('Database Error:  Couldn\'t query. br /' . mysql_error() . br
 /br / $this-query);
   } // End process

   function sanitize($ref)
   {
   $ref = mysql_real_escape_string($ref);
   } // End sanitize

 } // End do_mysql

 ?


 Sample usage:
 $value = 'value';
 $sql = new do_mysql();
 $sql-sanitize($value);
 $sql-query = SELECT * FROM `wherever` WHERE `field` = '$value';
 $sql-process('dbname');
 $sql-close();

 if ($sql-num_rows())
 {
   while ($row = $sql-fetch_array())
   {
   do stuff;
   }
 }


A couple of thoughts. First precede all your mysql_* calls with the at
sign (@) to shut up the routines if they generate text. I had this
problem, and that was the answer.

Second, store your connection resource as a class variable, so you can
pass it around to the various routines. Actually, you're already doing
this, but I prefer to do so explicitly, as:

var $link;

at the top of the class.

I have a similar class for PostgreSQL. I also have routines like
update, which allow you to pass a table name and an associative array
of field values. Same thing for an insert routine.

Paul

-- 
Paul M. Foster

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



Re: [PHP] About printing functions

2009-01-21 Thread Paul M Foster
On Wed, Jan 21, 2009 at 08:49:46PM +0200, Thodoris wrote:

snip


 Well Jason my point is theoretical. Lets just say that this function
 doesn't just print blah blah blah but like tones of html that you may
 like to reuse...

 Well you could always change it to this:

 function print_str() {
$str = blah blah blah;
return $str;
 }

 and use the output you got from the function whenever you like (print
 it, make it a toast, cook it with bees etc).

 But the question still remains: Is there a way to do this?

The only way to save this text off is to put it in a $_SESSION variable
or cookie, at least if you want to save it beyond the present page. Oh,
you could also store it in a database.

Paul

-- 
Paul M. Foster

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Richard Heyes
 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make it
 compatible with other databases.  I'm curious what you all think.

I have a similar thing I use, which uses the same (or at least very
similar) API to the PEAR::DB abstraction layer.

http://www.phpguru.org/downloads/DB/

-- 
Richard Heyes

HTML5 Graphing for Firefox, Chrome, Opera and Safari:
http://www.rgraph.org (Updated January 17th)

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



Re: [PHP] About printing functions

2009-01-21 Thread Török Alpár
2009/1/21 Edmund Hertle edmund.her...@student.kit.edu

 2009/1/21 Thodoris t...@kinetix.gr

 
 
  On Jan 21, 2009, at 1:33 PM, Thodoris wrote:
 
   Hi gang,
Lets say that you have a function that prints something to the output
  simply like this:
 
  function print_str() {
print blah blah blah;
  }
 
  I was wondering if there is a way to use this output and store it in a
  var or something without changing the function itself?
  And store the blah blah blah somewhere for later use?
 
  I can think of many reasons that someone could use this.
 
 
  I know you said without changing the function... but is there any reason
  that you can't simply add this:
 
  ?PHP
  function print_str() {
 $str = blah blah blah;
 print $str;
  }
  ?
 
  Totally untested and just trying to understand why :)
 
 
  --
  Jason Pruim
  japr...@raoset.com
  616.399.2355
 
 
 
 
 
  Well Jason my point is theoretical. Lets just say that this function
  doesn't just print blah blah blah but like tones of html that you may
 like
  to reuse...
 

  Well you could always change it to this:
 
  function print_str() {
$str = blah blah blah;
return $str;
  }
 
  and use the output you got from the function whenever you like (print it,
  make it a toast, cook it with bees etc).
 
  But the question still remains: Is there a way to do this?
 
 
  --
  Thodoris
 

 IMO it is always better to return strings than directly printing. there
 would be no problem even if it would contain tones of html...

Agree, but the solution suggested might come in handy if you have some
template files that you just include, and you don't want to write all that
html inside php strings.



 but what comes in my mind is output_buffering...
 see: http://de3.php.net/manual/en/book.outcontrol.php

 -eddy




-- 
Torok, Alpar Istvan


Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Jochem Maas
Paul M Foster schreef:
 On Wed, Jan 21, 2009 at 11:37:07AM -0600, Jay Moore wrote:
 
 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make
 it compatible with other databases.  I'm curious what you all think.


I'd try to move to using the mysqli functions or class, which
you can still wrap in a custom object (I do this because
I like to minimize the interface to the bare, bare minimum ...
professional laziness you might say).

does you class need to be php4 compatible? I'd hope
not but you may still have to support php4 ... even then
I'd doubt you'd be using php4 for new project so it
might be worth making a new php5 only class.

...

 Thanks,
 Jay

 Class:
 --
 ?php

 // Standard MySQL class
 class do_mysql
 {
  // Constructor
  function __construct()
  {
  $this-do_mysql();
  }

  // Destructor
  function __destruct()
  {
  //$this-close();
  }

  function do_mysql()
  {
  $this-login = '';
  $this-pass = '';

  $this-link = @mysql_connect('localhost', $this-login,
  $this-pass)
 or die('Could not connect to the database.');
  } // End do_mysql

  // Functions
  function close()
  {
  if ($this-link)
  {
  mysql_close($this-link);
  unset($this-link);
  }
  } // End close

  function fetch_array()
  {
  return mysql_fetch_array($this-result);
  } // End fetch_array

  function last_id()
  {
  return mysql_insert_id($this-link);
  } // End last_id

  function num_rows()
  {
  return mysql_num_rows($this-result);
  } // End num_rows

  function process($database = '')
  {
  if (is_null($this-query))
  {
  die('Error:  Query string empty.  Cannot proceed.');
  }

  $this-db = @mysql_select_db($database, $this-link)
  or die(Database
 Error:   Couldn't select $database br / . mysql_error());
  $this-result = @mysql_query($this-query, $this-link) or
 die('Database Error:  Couldn\'t query. br /' . mysql_error() . br
 /br / $this-query);
  } // End process

  function sanitize($ref)
  {
  $ref = mysql_real_escape_string($ref);
  } // End sanitize

 } // End do_mysql

 ?


 Sample usage:
 $value = 'value';
 $sql = new do_mysql();
 $sql-sanitize($value);
 $sql-query = SELECT * FROM `wherever` WHERE `field` = '$value';
 $sql-process('dbname');
 $sql-close();

 if ($sql-num_rows())
 {
  while ($row = $sql-fetch_array())
  {
  do stuff;
  }
 }

 

here's another (php5) version of your class,
see what you think:

?php

class do_mysql
{
private $link;
private $result;
private $db;

// Constructor
function __construct($login, $pass, $db, $server = 'localhost')
{
$this-link = mysql_connect($server, $login, $pass);

if (!$this-link)
throw new Exception('Could not connect to the database.');

$this-setDB($db);
}

// Destructor
function __destruct()
{
$this-close();
}

// Functions
function close()
{
if (!$this-link)
return;

mysql_close($this-link);
unset($this-link);

}

function fetch_array()
{
return mysql_fetch_array($this-result);
}

function last_id()
{
return mysql_insert_id($this-link);
}

function num_rows()
{
return mysql_num_rows($this-result);
}

function setDB($database)
{
if (!$database || !mysql_select_db($database, $this-link))
throw new Exception(Database Error:  Couldn't select $database 
-  . mysql_error());
}

function query($query)
{
if (empty($query))
throw new Exception('Error:  Query string empty.  Cannot 
proceed.');

$this-result = mysql_query($this-query, $this-link);

if (!$this-result) // beware that putting this msg on screen is a 
security hazard
throw new Exception('Database Error:  Couldn\'t query - ' . 
mysql_error() .  - $query);
}

function escape($ref)
{
return mysql_real_escape_string($ref, $this-link);
}

}

 A couple of thoughts. First precede all your mysql_* calls with the at
 sign (@) to shut up the routines if they generate text. I had this
 problem, and that was the answer.

yes that's very bad advice. using error suppression is bad for performance
and debugging, don't do it unless you really really have to (e.g. you
have some function that spits warnings even with display_errors set to Off)

display_errors should be set to Off in production, and errors/warnings shouldn't
be suppressed, they should be logged.

handle 

Re: [PHP] Military - Standard times

2009-01-21 Thread Jochem Maas
tedd schreef:
 Hi gang:

would you stop calling me that, I'll bet it means something rude in korean. :-P

 What's the slickest way to go from standard to military times and back
 again?

wouldn't the slickest way be to carry/store unixtimestamps and
then output whatever version you need when you need it,
the conversion back and forth *seems* pointless.

 
 Such as:
 
 0800 - 8:00am
 8:00am - 0800
 
 -- or --
 
 1600 - 4:00pm
 4:00pm - 1600
 
 I use the following functions, but is there anything better?
 
 function standardToMilitary($t)
{
$t = strftime('%R', strtotime($t));
return $t;

what's with the superfluous variable?
why not just:

return strftime('%R', strtotime($t));

also, small point, if you came across the function
militaryToStandard() somewhere in the code, how would
one know if it were all about about time formats
or elephants?

}
 
 function militaryToStandard($t)
{
$t = strftime('%r', strtotime($t));
return $t;
}
 
 Thanks,
 
 tedd

PS - I think the best ever name for a Exception class is 'Tantrum':

throw new Tantrum('Ra Ra Ra Aaaargh');

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Philip Graham


On January 21, 2009 12:37:07 Jay Moore wrote:
 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make
 it compatible with other databases.  I'm curious what you all think.

I definetly think that using a DB class is a really good idea, but the 
interface to your object could use some improvement.


 Sample usage:
 $value = 'value';
 $sql = new do_mysql();
 $sql-sanitize($value);
 $sql-query = SELECT * FROM `wherever` WHERE `field` = '$value';
 $sql-process('dbname');
 $sql-close();

 if ($sql-num_rows())
 {
   while ($row = $sql-fetch_array())
   {
   do stuff;
   }
 }

One of the goals of encapsulating DB access should be to hide some of the 
tediousness of database access, however, using the interface for your object 
you're still writing just as many (if not more) lines of code as you would by 
simply using the mysql_* functions directly.

As an example of how you can put this into practice, here's the interface to 
the DB object that I use:

The object is implemented as a singleton.  When retrieved initially the 
constructor deals with setting up the connection using constant defined in the 
class for username, password, dbName and server address.  The instance itself 
wraps a PDO connection and provides the following interface:

// Query functions
query($query, $queryName = null, $taskName = null);
prepare($query, $queryName, $taskName = null);
execute($queryName, array $params = array(), $taskName = null);
static sanitize($string);

// Data retrieval functions
getResults($queryName, $taskName = null);
getColumn($queryName, $taskName = null, $columnIndex = 0);
getRow($queryName, $taskName = null, $rowIndex = 0);
getCell($queryName, $taskName = null, $rowIndex = 0, $columnIndex = 0);

// Storage control
reset($queryName, $taskName = null);
resetAll($taskName = null);

The interface is clean and lets me handle most common cases with readable 
code:

// Retrieve one piece of data from the database
try {
$db = DB::getInstance();
$db-prepare('SELECT COUNT(*) FROM users WHERE id=:userid', 
'getNumUsers');
$db-execute('getNumUsers', array(':userid' = $userId));
$numUsers = $db-getCell('getNumUsers');

// Retrieve a row from the database
if($numUsers == 1) {
$db-prepare('SELECT * FROM users WHERE id=:userid', 
'getUserInfo');
$db-execute('getUserInfo', array(':userid' = $userId));
$userInfo = $db-getRow('getUserInfo');

// Retrieve multiple rows from the data
$db-prepare('SELECT friend_id FROM user_friends WHERE 
user_id=:userid', 
'getUsersFriends');
$db-execute('getUsersFriends', array(':userid' = $userId));
foreach($db-getColumn('getUsersFriends') AS $friendId) {
$db-execute('getUserInfo', array(':userid'= 
$friendId));
$friendInfo = $db-getRow('getUserInfo');
// .
}
}
$db-reset('getNumUsers');
$db-reset('getUserInfo');
$db-reset('getUsersFiends');
} catch(DBException $exception) {
echo $exception;
}

Since the object wraps a PDO object, there's no need to sanitize, just 
parameterize anything that may be unsafe in a prepared statement.  The 
retrieval functions will all return the data in a form that's easy to access 
so you don't need to worry about getting an associative array when all you 
want is a single cell or worry about getting a table when all you want is a 
single row.  This helps to reduces clutter in your code.  Any PDOExceptions 
are wrapped with the DBException class that implements an __toString method 
that outputs a nice message to make error output clean and consistent.

The interface for you object does little more than replace the mysql_* 
function calls with calls to an equivalent function in your oject.

Re-writing your example from above:

$db = DB::getInstance();
$value = 'value';
$db-prepare('SELECT * FROM wherever WHERE field=:val, 'getData');
$db-execute('getData', array(':val' = $value));
foreach($db-getResults('getData') AS $row) {
// Do stuff
}

Resulting in a reduction of 5 lines of code.  I may not sound that impressive 
for a small example but over the number of times you generally access a 
database it will really add up.
 
-- 
Philip Graham
Lightbox Technologies
www.lightbox.org

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



Re: [PHP] Suggested diagramming package for php application

2009-01-21 Thread Jochem Maas
Anne Watelet schreef:
 Hi - we currently use visio for creating basic block diagrams and save
 these as images to our web site so others can view them. What we really
 would like to do is to have our php application be able to display the
 diagram and then upon clicking an edit button, allow the user to edit
 the diagram directly. We are currently using php 5 and postgresql 8.2 on
 an Ubuntu server. I was wondering if anyone had any suggestions on an
 open source package that would allow us to do this functionality? Thank
 you in advance for any help or insight!

I recommend STFW:

http://www.gliffy.com
http://www.flowchart.com
http://www.drawanywhere.com

coolest I found in 5 mins of looking around:

http://www.mxgraph.com/demo/mxgraph/editors/workfloweditor.html


 


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



Re: [PHP] Military - Standard times

2009-01-21 Thread Nitsan Bin-Nun
Umm I don't think there is a better option, you probably can return the
output straight:

function standardToMilitary($t)
  {
  return strftime('%R', strtotime($t));
  }

function militaryToStandard($t)
  {
  return strftime('%r', strtotime($t));
  }

But it doesn't really matter.

On Wed, Jan 21, 2009 at 9:16 PM, tedd t...@sperling.com wrote:

 Hi gang:

 What's the slickest way to go from standard to military times and back
 again?

 Such as:

 0800 - 8:00am
 8:00am - 0800

 -- or --

 1600 - 4:00pm
 4:00pm - 1600

 I use the following functions, but is there anything better?

 function standardToMilitary($t)
   {
   $t = strftime('%R', strtotime($t));
   return $t;
   }

 function militaryToStandard($t)
   {
   $t = strftime('%r', strtotime($t));
   return $t;
   }

 Thanks,

 tedd
 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com

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




Re: [PHP] Suggested diagramming package for php application

2009-01-21 Thread Anne Watelet
Thank you - I'll take a look!

On Wed, Jan 21, 2009 at 3:28 PM, Jochem Maas joc...@iamjochem.com wrote:

 Anne Watelet schreef:
  Hi - we currently use visio for creating basic block diagrams and save
  these as images to our web site so others can view them. What we really
  would like to do is to have our php application be able to display the
  diagram and then upon clicking an edit button, allow the user to edit
  the diagram directly. We are currently using php 5 and postgresql 8.2 on
  an Ubuntu server. I was wondering if anyone had any suggestions on an
  open source package that would allow us to do this functionality? Thank
  you in advance for any help or insight!

 I recommend STFW:

 http://www.gliffy.com
 http://www.flowchart.com
 http://www.drawanywhere.com

 coolest I found in 5 mins of looking around:

 http://www.mxgraph.com/demo/mxgraph/editors/workfloweditor.html


 




Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Jay Moore

Good ideas guys.  The input is much appreciated.

Jochem (and anyone else, I guess), as I am not 100% versed with 
Exceptions, the php5 version you suggested, are those Exceptions able to 
be handled outside the class?


Do I need my try block to be within the class block, or can I have the 
try block be in my normal code where I actually instantiate the class?


This:

class blah
{
try { stuff } catch (exception) { more stuff }
}

$i = new blah()

or can I do this:

class blah
{
do some stuff (no try/catch blocks here)
throw an exception
}

try
{

$i = new blah();
more stuff
}
catch (exception) { even more stuff }


Thanks,
Jay

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



Re: [PHP] Suggested diagramming package for php application

2009-01-21 Thread Anne Watelet
These are on-line services from what I can see. We are working with IP so
would need to install the software on our server and integrate it directly
into our applications. If anyone else has any suggestions let me know -
thank you again!

On Wed, Jan 21, 2009 at 3:28 PM, Jochem Maas joc...@iamjochem.com wrote:

 Anne Watelet schreef:
  Hi - we currently use visio for creating basic block diagrams and save
  these as images to our web site so others can view them. What we really
  would like to do is to have our php application be able to display the
  diagram and then upon clicking an edit button, allow the user to edit
  the diagram directly. We are currently using php 5 and postgresql 8.2 on
  an Ubuntu server. I was wondering if anyone had any suggestions on an
  open source package that would allow us to do this functionality? Thank
  you in advance for any help or insight!

 I recommend STFW:

 http://www.gliffy.com
 http://www.flowchart.com
 http://www.drawanywhere.com

 coolest I found in 5 mins of looking around:

 http://www.mxgraph.com/demo/mxgraph/editors/workfloweditor.html


 




Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Paul M Foster
On Wed, Jan 21, 2009 at 09:10:54PM +0100, Jochem Maas wrote:

 Paul M Foster schreef:
  On Wed, Jan 21, 2009 at 11:37:07AM -0600, Jay Moore wrote:
 
  This is a MySQL class I use and I wanted to get everyone's thoughts on
  how/if I can improve it.  This is for MySQL only.  I don't need to make
  it compatible with other databases.  I'm curious what you all think.
 
 
 I'd try to move to using the mysqli functions or class, which
 you can still wrap in a custom object (I do this because
 I like to minimize the interface to the bare, bare minimum ...
 professional laziness you might say).
 
 does you class need to be php4 compatible? I'd hope
 not but you may still have to support php4 ... even then
 I'd doubt you'd be using php4 for new project so it
 might be worth making a new php5 only class.

I always write with PHP4 in mind. You never know. Besides, I can always
change the internal implementation, if it's a class.

snip

 
  A couple of thoughts. First precede all your mysql_* calls with the at
  sign (@) to shut up the routines if they generate text. I had this
  problem, and that was the answer.
 
 yes that's very bad advice. using error suppression is bad for performance
 and debugging, don't do it unless you really really have to (e.g. you
 have some function that spits warnings even with display_errors set to Off)
 
 display_errors should be set to Off in production, and errors/warnings
 shouldn't
 be suppressed, they should be logged.
 
 handle errors gracefully ('or die()' is not graceful)

I don't know about performance. But every call to the query() method of
my class tests to see the results of the query. If it failed, I call the
proper function from PostgreSQL to fetch the error, and store it in the
class. The query function returns false, if there's an error. So the
user can test the return and then call a function to echo the stored
error.


 
  Second, store your connection resource as a class variable, so you can
  pass it around to the various routines. Actually, you're already doing
  this, but I prefer to do so explicitly, as:
 
  var $link;
 
 that's very php4.

Yep.

 
  at the top of the class.
 
  I have a similar class for PostgreSQL. I also have routines like
  update, which allow you to pass a table name and an associative array
  of field values. Same thing for an insert routine.
 
 if the postgres extension is anything like the firebird extension then
 there may actually be a few calls which do require error suppression :-)
 

Probably. When I first started coding PHP/PostgreSQL, I was getting
stuff printed out from the pg_* routines on the webpages and screwing
things up. I was on the PostgreSQL list at the time, and sent an email
to the list about chatter from the pg_* routines. The solution was to
prefix them with @. Works great, but I *do* check for and capture error
text and such.

Paul

-- 
Paul M. Foster

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Paul M Foster
On Wed, Jan 21, 2009 at 02:30:00PM -0600, Jay Moore wrote:

 Good ideas guys.  The input is much appreciated.

 Jochem (and anyone else, I guess), as I am not 100% versed with
 Exceptions, the php5 version you suggested, are those Exceptions able to
 be handled outside the class?

 Do I need my try block to be within the class block, or can I have the
 try block be in my normal code where I actually instantiate the class?

 This:

 class blah
 {
   try { stuff } catch (exception) { more stuff }
 }

 $i = new blah()

 or can I do this:

 class blah
 {
   do some stuff (no try/catch blocks here)
   throw an exception
 }

 try
 {

   $i = new blah();
   more stuff
 }
 catch (exception) { even more stuff }


I know it's very OO-y to use exceptions, but I hate them. They're like
setjmp/longjmp calls in C, and they're a really headache to deal with.
If you don't use default or predone handlers, you have to put all kinds
of try/catch blocks around everything. They make for non-linear
execution, and I prefer my code to execute in a linear fashion.

Paul

-- 
Paul M. Foster

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Jochem Maas
Jay Moore schreef:
 Good ideas guys.  The input is much appreciated.
 
 Jochem (and anyone else, I guess), as I am not 100% versed with
 Exceptions, the php5 version you suggested, are those Exceptions able to
 be handled outside the class?
 
 Do I need my try block to be within the class block, or can I have the
 try block be in my normal code where I actually instantiate the class?
 
 This:
 
 class blah
 {
 try { stuff } catch (exception) { more stuff }
 }
 
 $i = new blah()

no, this does not work, 'snot even valid syntax.

 
 or can I do this:
 
 class blah
 {
 do some stuff (no try/catch blocks here)
 throw an exception
 }
 
 try
 {
 
 $i = new blah();
 more stuff
 }
 catch (exception) { even more stuff }

yes.

try {
$db = new do_mysql('root', 'pass', 'mydb');
} catch (Exception $e) {
// var_dump($e); // debug
// could not connect, deal with it.
}

// do some stuff

try {
$db-query($myQry);
} catch (Exception $e) {
// bad query, deal with
}

... etc, etc

 Thanks,
 Jay
 


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



Re: [PHP] Redirecting from unreachable page on website

2009-01-21 Thread Jochem Maas
Per Jessen schreef:
 Dušan Novaković wrote:
 
 Hi,

 Is there some elegant solution how to redirect if someone try to open
 some non existing page (e.g www.domain.com/nonexistingpage.php) to
 main page www.domain.com on website?

 
 See Apache ErrorDocument directive.


ai,

ErrorDocument 404   /404.php

?php // 404.php

// do something with query args?

// or just redirect
header('Location: /'); // there should really be FQDN there, but I never bother.
?

or just have apache do all of it ... having a php script
handle the 404 allows you to do fun things with requested URI, GET string, etc

 
 /Per Jessen, Zürich
 
 


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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Jay Moore



I know it's very OO-y to use exceptions, but I hate them. They're like
setjmp/longjmp calls in C, and they're a really headache to deal with.
If you don't use default or predone handlers, you have to put all kinds
of try/catch blocks around everything. They make for non-linear
execution, and I prefer my code to execute in a linear fashion.

Paul



My thoughts exactly.  What do I gain by using a try/catch that I lose by 
using if/else or similar?


J

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Jochem Maas
Jay Moore schreef:
 
 I know it's very OO-y to use exceptions, but I hate them. They're like
 setjmp/longjmp calls in C, and they're a really headache to deal with.
 If you don't use default or predone handlers, you have to put all kinds
 of try/catch blocks around everything. They make for non-linear
 execution, and I prefer my code to execute in a linear fashion.

 Paul

 
 My thoughts exactly.  What do I gain by using a try/catch that I lose by
 using if/else or similar?

you use them not for control flow, but for deferring exceptional application
states, which you can then handle in a small number of places as opposed
to scattering the error handling of unlikely events in all sorts of
disparate places.

there is an art to using them, they compliment 'traditional' error handling,
and I agree they can hinder if used badly.

NB: you can have multiple catch blocks:

try {
// do lots of stuff
} catch (ConnectException $e) {

} catch (QueryException $e) {

} catch (DBSelectException $e) {

} catch (Exception $e) {
// catch all for stuff we don't handle specifically
}

 J
 


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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Török Alpár
2009/1/21 Jay Moore jaymo...@accu-com.com


  I know it's very OO-y to use exceptions, but I hate them. They're like
 setjmp/longjmp calls in C, and they're a really headache to deal with.
 If you don't use default or predone handlers, you have to put all kinds
 of try/catch blocks around everything. They make for non-linear
 execution, and I prefer my code to execute in a linear fashion.

 this also means you use a single return in a function ?



 Paul


 My thoughts exactly.  What do I gain by using a try/catch that I lose by
 using if/else or similar?

the power to omit it, and then change your mind  lather, and handle them.
The only problem is that php itself (nor core, nor extensions) throw
exceptions, so you can't threat errors uniformly, but you cant have a custom
error handler, and throw exceptions from there, and you can also have an
exception handler. I have used this approach in several projects, and i
admit it takes some getting used to, but it's an easy, clean, nice way to
handle exceptions / errors / conditions.



 J

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




-- 
Torok, Alpar Istvan


Re: Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread ceo

 there is an art to using them, they compliment 'traditional' error

 handling, and I agree they can hinder if used badly.



I don't think I've ever seen Exceptions used well...



Invariably, I end up having to write a wrapper function around every function 
implemented and catch all the Exceptions.



Otherwise, my code is littered with try/catch blocks for every little thing the 
other guy was too lazy to figure out how to handle gracefully.



ymmv



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



Re: [PHP] Military - Standard times

2009-01-21 Thread Nathan Rixham

Jochem Maas wrote:

tedd schreef:

Hi gang:


would you stop calling me that, I'll bet it means something rude in korean. :-P


What's the slickest way to go from standard to military times and back
again?


wouldn't the slickest way be to carry/store unixtimestamps and
then output whatever version you need when you need it,
the conversion back and forth *seems* pointless.



agree completely, seperate out the display so you have

function militaryTime($t)
{
  return strftime('%R', $t);
}

function standardTime($t)
{
  return strftime('%r', $t);
}

$time = time();
$militaryTime = militaryTime($time);
$standardTime = standardTime($time);

=
but then you could shorten to:

function timeFormat($militaryTime = FALSE) {
  $format = $militaryTime ? '%R' : '%r';
  return strftime($format, $t);
}
$time = time();
$militaryTime = timeFormat(TRUE);
$standardTime = timeFormat();

=
or you could leave you're options open and go for:

function timeFormat($format = '%r') {
  return strftime($format, $t);
}
$time = time();
$militaryTime = timeFormat('%r');

=
or just
$time = time();
$militaryTime = strftime('%r', $time);

:P


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



[PHP] Time Wrong

2009-01-21 Thread Gary
Im pretty new with php, so this might be a pretty novice mistake, but the 
time displays wrong on two computers.

  ?php echo date('l F jS, o h i A');?

Shows up 2 hours late...time on both computers is correct.

Thanks 



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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Nathan Rixham

c...@l-i-e.com wrote:

there is an art to using them, they compliment 'traditional' error
handling, and I agree they can hinder if used badly.


I don't think I've ever seen Exceptions used well...

Invariably, I end up having to write a wrapper function around every function 
implemented and catch all the Exceptions.

Otherwise, my code is littered with try/catch blocks for every little thing the 
other guy was too lazy to figure out how to handle gracefully.

ymmv



i use them often, basically if a boolean false won't do its a case of 
throwing an exception.


let's say you have:

calls_fifty_methods($page_load_of_variables);

wrap that bit in a try catch and you get


try {

  calls_fifty_methods($page_load_of_variables);

} catch ( DatabaseException $e) {
  // handle that error
} catch ( FileNotFoundException $e) {
  // handle
} catch ( VerySpecificException) {
  // handle
} catch ( Exception $e ) {
  // didn't expect this, notify devs, error log it and do X Y Z
}

try firing back error codes or something from 50 methods down and you 
have a real can go wrong easily series of returning error codes and 
processing the same anyways; or you could take the echo some html 
approach from the function - which is wrong on so many levels or..


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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Paul M Foster
On Wed, Jan 21, 2009 at 10:00:53PM +0100, Jochem Maas wrote:

 Jay Moore schreef:
 
  I know it's very OO-y to use exceptions, but I hate them. They're like
  setjmp/longjmp calls in C, and they're a really headache to deal with.
  If you don't use default or predone handlers, you have to put all kinds
  of try/catch blocks around everything. They make for non-linear
  execution, and I prefer my code to execute in a linear fashion.
 
  Paul
 
 
  My thoughts exactly.  What do I gain by using a try/catch that I lose by
  using if/else or similar?
 
 you use them not for control flow, but for deferring exceptional application
 states, which you can then handle in a small number of places as opposed
 to scattering the error handling of unlikely events in all sorts of
 disparate places.
 
 there is an art to using them, they compliment 'traditional' error handling,
 and I agree they can hinder if used badly.

I understand, but then it comes down to how you define an exceptional
application state. If I build a date class that throws exceptions, it's
very OO-y, but a waste of my programmer time. I could just as easily
build an error checker into the class and use that to check for errors.
Generally speaking, my next step is going to be to display the page
again and tell the user to retype the date properly anyway.

There are reasons to use setjmp and longjmp in C as well, but I only
ever used them once, and later ripped out that code.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Time Wrong

2009-01-21 Thread Edmund Hertle
2009/1/21 Gary gwp...@ptd.net

 Im pretty new with php, so this might be a pretty novice mistake, but the
 time displays wrong on two computers.

  ?php echo date('l F jS, o h i A');?

 Shows up 2 hours late...time on both computers is correct.

 Thanks


Do you mean on two computers visiting a php script? PHP is running on the
server, so it will use server time
-eddy


Re: [PHP] Time Wrong

2009-01-21 Thread Nathan Rixham

Edmund Hertle wrote:

2009/1/21 Gary gwp...@ptd.net


Im pretty new with php, so this might be a pretty novice mistake, but the
time displays wrong on two computers.

 ?php echo date('l F jS, o h i A');?

Shows up 2 hours late...time on both computers is correct.

Thanks



Do you mean on two computers visiting a php script? PHP is running on the
server, so it will use server time
-eddy



makes sense.. check out http://php.net/date_default_timezone_set - 
probaly needs set


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



Re: [PHP] Time Wrong

2009-01-21 Thread Gary
Thanks for all the replies, I was able to set the time zone with one of the 
tutorials.

Thanks again

Gary
Nathan Rixham nrix...@gmail.com wrote in message 
news:49779f04.4060...@gmail.com...
 Edmund Hertle wrote:
 2009/1/21 Gary gwp...@ptd.net

 Im pretty new with php, so this might be a pretty novice mistake, but 
 the
 time displays wrong on two computers.

  ?php echo date('l F jS, o h i A');?

 Shows up 2 hours late...time on both computers is correct.

 Thanks


 Do you mean on two computers visiting a php script? PHP is running on the
 server, so it will use server time
 -eddy


 makes sense.. check out http://php.net/date_default_timezone_set - probaly 
 needs set 



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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Jochem Maas
Nathan Rixham schreef:
 c...@l-i-e.com wrote:
 there is an art to using them, they compliment 'traditional' error
 handling, and I agree they can hinder if used badly.

 I don't think I've ever seen Exceptions used well...

 Invariably, I end up having to write a wrapper function around every
 function implemented and catch all the Exceptions.

 Otherwise, my code is littered with try/catch blocks for every little
 thing the other guy was too lazy to figure out how to handle gracefully.

 ymmv

 
 i use them often, basically if a boolean false won't do its a case of
 throwing an exception.
 
 let's say you have:
 
 calls_fifty_methods($page_load_of_variables);
 
 wrap that bit in a try catch and you get
 
 
 try {
 
   calls_fifty_methods($page_load_of_variables);
 
 } catch ( DatabaseException $e) {
   // handle that error
 } catch ( FileNotFoundException $e) {
   // handle
 } catch ( VerySpecificException) {
   // handle
 } catch ( Exception $e ) {
   // didn't expect this, notify devs, error log it and do X Y Z
 }
 
 try firing back error codes or something from 50 methods down and you
 have a real can go wrong easily series of returning error codes and
 processing the same anyways; or you could take the echo some html
 approach from the function - which is wrong on so many levels or..
 

agreed, that basically the point, being able to defer the handling of
the problem to some code that knows what to do with it given the context,
if a DB object cannot connect to the DB how does it know what to do in
terms of handling the situation? ... in a webpage you may wish to
redirect, show an error msg or something else (which shouldn't be up
to the object in question and should therefore not be built into it),
in a CLI environment you'd want to do something else maybe.

wrapper functions to handle exceptions as Richard offered is actually
quite neat assuming that the wrapper functions are designed for a
given context (and that they can then assume to be able to handle
the given exception in a way suitable to the given context)

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Chris

Eric Butera wrote:

On Wed, Jan 21, 2009 at 12:45 PM, Edmund Hertle
edmund.her...@student.kit.edu wrote:

2009/1/21 Jay Moore jaymo...@accu-com.com


This is a MySQL class I use and I wanted to get everyone's thoughts on
how/if I can improve it.  This is for MySQL only.  I don't need to make it
compatible with other databases.  I'm curious what you all think.

Thanks,
Jay


Hey,
1. You know the mysqli-Class?
2. If yes, than I don't get it in which way this will improve mysql handling

 -eddy



Yea if you're only targeting 1 db, then why not use that class?  At
least then there's the php manual to figure out what something does.


Because then to add query logging for the whole app, you just need to 
put it in the class :)


(I've done that before to check what's being run and where from, comes 
in very handy).


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


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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread ceo

I prefer to deal with the issues locally, or have a documented behaviour with 
return values and error details available, much like most of PHP 
extensions/internals.



try/catch ends up with weird code organization, imho, especially when you can 
only really handle some exceptions.



For real fun, one API layer will catch all the lower exceptions, then wrap them 
in a generic exception, and you have to string parse $e-getMessage() to figure 
out what to *do*. [shudder]



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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 5:53 PM, Chris dmag...@gmail.com wrote:
 Eric Butera wrote:

 On Wed, Jan 21, 2009 at 12:45 PM, Edmund Hertle
 edmund.her...@student.kit.edu wrote:

 2009/1/21 Jay Moore jaymo...@accu-com.com

 This is a MySQL class I use and I wanted to get everyone's thoughts on
 how/if I can improve it.  This is for MySQL only.  I don't need to make
 it
 compatible with other databases.  I'm curious what you all think.

 Thanks,
 Jay

 Hey,
 1. You know the mysqli-Class?
 2. If yes, than I don't get it in which way this will improve mysql
 handling

  -eddy


 Yea if you're only targeting 1 db, then why not use that class?  At
 least then there's the php manual to figure out what something does.

 Because then to add query logging for the whole app, you just need to put it
 in the class :)

 (I've done that before to check what's being run and where from, comes in
 very handy).

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



That's done by tail -f /var/log/mysql/query.log. :D

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Chris



Yea if you're only targeting 1 db, then why not use that class?  At
least then there's the php manual to figure out what something does.

Because then to add query logging for the whole app, you just need to put it
in the class :)

(I've done that before to check what's being run and where from, comes in
very handy).





That's done by tail -f /var/log/mysql/query.log. :D


That won't tell you where a query comes from ;) Add a debug_backtrace 
into the class to also pinpoint where the query was called from. 
Complicated queries built on variables (or even just long queries built 
over multiple lines) will be hard to find just by looking at the mysql 
query log.


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


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



Re: [PHP] About printing functions

2009-01-21 Thread Mattias Thorslund

Thodoris wrote:

Hi gang,
   Lets say that you have a function that prints something to the 
output simply like this:


function print_str() {
   print blah blah blah;
}

I was wondering if there is a way to use this output and store it in a 
var or something without changing the function itself?

And store the blah blah blah somewhere for later use?

I can think of many reasons that someone could use this.



Perhaps you are looking for what the output buffering functions do?

http://us3.php.net/manual/en/book.outcontrol.php

Cheers,

Mattias



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



Re: [PHP] Military - Standard times

2009-01-21 Thread tedd

At 9:19 PM +0100 1/21/09, Jochem Maas wrote:

tedd schreef:

 Hi gang:


would you stop calling me that, I'll bet it means something rude in 
korean. :-P


Hey, you called me schreef and that means an end of a stroke 
(Arrggg, that has all sorts of meanings).  :-)



wouldn't the slickest way be to carry/store unixtimestamps and
then output whatever version you need when you need it,
the conversion back and forth *seems* pointless.


I'm into pointless stuff -- I'm symmetrically challenged. I don't 
like doing anything that can't be undone.



what's with the superfluous variable?
why not just:

return strftime('%R', strtotime($t));


I like superfluous code -- it makes me feel better and I like to see 
the computer work (while they still work for us).


Besides, oddly enough I can understand

   return $t;

better than

   return strftime('%R', strtotime($t));



also, small point, if you came across the function
militaryToStandard() somewhere in the code, how would
one know if it were all about about time formats
or elephants?


Good point, I should have used

militaryToStandardElephants()

Thanks,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Military - Standard times

2009-01-21 Thread tedd

At 9:06 PM + 1/21/09, Nathan Rixham wrote:

-snip-

:P



It's a good thing I didn't ask for anything complicated. :-)

Thanks.

And what's with everyone sticking out their tongue?  :-P

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 6:09 PM, Chris dmag...@gmail.com wrote:

 Yea if you're only targeting 1 db, then why not use that class?  At
 least then there's the php manual to figure out what something does.

 Because then to add query logging for the whole app, you just need to put
 it
 in the class :)

 (I've done that before to check what's being run and where from, comes in
 very handy).



 That's done by tail -f /var/log/mysql/query.log. :D

 That won't tell you where a query comes from ;) Add a debug_backtrace into
 the class to also pinpoint where the query was called from. Complicated
 queries built on variables (or even just long queries built over multiple
 lines) will be hard to find just by looking at the mysql query log.

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



I've been using it for 5 years now and haven't had problems.  Then
again I still write sql by hand too.  I only use it when something is
acting really weird and I'm having a hard time.  So it is a targeted
process where I know what I'm looking for.

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



Re: [PHP] Military - Standard times

2009-01-21 Thread Jochem Maas
tedd schreef:
 At 9:19 PM +0100 1/21/09, Jochem Maas wrote:
 tedd schreef:
  Hi gang:

 would you stop calling me that, I'll bet it means something rude in
 korean. :-P
 
 Hey, you called me schreef and that means an end of a stroke
 (Arrggg, that has all sorts of meanings).  :-)

which translation service came up with that?? it is funny though :-)

 
 wouldn't the slickest way be to carry/store unixtimestamps and
 then output whatever version you need when you need it,
 the conversion back and forth *seems* pointless.
 
 I'm into pointless stuff -- I'm symmetrically challenged. I don't like
 doing anything that can't be undone.

and how many kids do you have :-P

 what's with the superfluous variable?
 why not just:

 return strftime('%R', strtotime($t));
 
 I like superfluous code -- it makes me feel better and I like to see the
 computer work (while they still work for us).

since I left Windows I find it works against me less.

 
 Besides, oddly enough I can understand
 
return $t;
 
 better than
 
return strftime('%R', strtotime($t));

now that's plain weird. is it because '$t' vaguely resembles a rock[tm]?

 
 also, small point, if you came across the function
 militaryToStandard() somewhere in the code, how would
 one know if it were all about about time formats
 or elephants?
 
 Good point, I should have used
 
 militaryToStandardElephants()

what would hannibal say?

PS - I'm sure this is too kafkaesque for some.
PPS - I have a little rock with the words the ball is round carved into it?
not your work by any chance?

:-D


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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Jochem Maas
Chris schreef:
 
 Yea if you're only targeting 1 db, then why not use that class?  At
 least then there's the php manual to figure out what something does.
 Because then to add query logging for the whole app, you just need to
 put it
 in the class :)

 (I've done that before to check what's being run and where from,
 comes in
 very handy).

 

 That's done by tail -f /var/log/mysql/query.log. :D
 
 That won't tell you where a query comes from ;) Add a debug_backtrace
 into the class to also pinpoint where the query was called from.
 Complicated queries built on variables (or even just long queries built
 over multiple lines) will be hard to find just by looking at the mysql
 query log.
 

besides on shared hosting that log is often turned off even if you can get at 
it.


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



[PHP] Re: MySQL class. Thoughts?

2009-01-21 Thread Al



Jay Moore wrote:
This is a MySQL class I use and I wanted to get everyone's thoughts on 
how/if I can improve it.  This is for MySQL only.  I don't need to make 
it compatible with other databases.  I'm curious what you all think.


Thanks,
Jay

Class:
--
?php

// Standard MySQL class
class do_mysql
{   
// Constructor

function __construct()
{
$this-do_mysql();
}

// Destructor

function __destruct()
{
//$this-close();
}

function do_mysql()

{
$this-login = '';
$this-pass = '';
   
$this-link = @mysql_connect('localhost', $this-login, 
$this-pass) or die('Could not connect to the database.');

} // End do_mysql

// Functions   
function close()

{
if ($this-link)
{
mysql_close($this-link);
unset($this-link);
}
} // End close

function fetch_array()

{
return mysql_fetch_array($this-result);
} // End fetch_array

function last_id()

{
return mysql_insert_id($this-link);
} // End last_id
   
function num_rows()

{
return mysql_num_rows($this-result);
} // End num_rows

function process($database = '')

{
if (is_null($this-query))
{
die('Error:  Query string empty.  Cannot proceed.');
}
   
$this-db = @mysql_select_db($database, $this-link) or 
die(Database Error:  Couldn't select $database br / . mysql_error());
$this-result = @mysql_query($this-query, $this-link) or 
die('Database Error:  Couldn\'t query. br /' . mysql_error() . br 
/br / $this-query);

} // End process

function sanitize($ref)

{
$ref = mysql_real_escape_string($ref);
} // End sanitize

} // End do_mysql


?


Sample usage:
$value = 'value';
$sql = new do_mysql();
$sql-sanitize($value);
$sql-query = SELECT * FROM `wherever` WHERE `field` = '$value';
$sql-process('dbname');
$sql-close();

if ($sql-num_rows())
{
while ($row = $sql-fetch_array())
{
do stuff;
}
}


I think I'd use one of 20+ Pear classes. They are pretty throughly tested 
because of the thousands of users.


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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 6:37 PM, Jochem Maas joc...@iamjochem.com wrote:
 Chris schreef:

 Yea if you're only targeting 1 db, then why not use that class?  At
 least then there's the php manual to figure out what something does.
 Because then to add query logging for the whole app, you just need to
 put it
 in the class :)

 (I've done that before to check what's being run and where from,
 comes in
 very handy).



 That's done by tail -f /var/log/mysql/query.log. :D

 That won't tell you where a query comes from ;) Add a debug_backtrace
 into the class to also pinpoint where the query was called from.
 Complicated queries built on variables (or even just long queries built
 over multiple lines) will be hard to find just by looking at the mysql
 query log.


 besides on shared hosting that log is often turned off even if you can get at 
 it.



That's why I set up a local dev environment.  If something is wrong,
just grab a db dump  figure it out locally.  That way I can do
whatever I need to really try out what the issue is and the best way
to resolve it.

Just merely saying how I develop.  Whatever gets it done is the real way. :)

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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Ashley Sheridan
On Wed, 2009-01-21 at 18:52 -0500, Eric Butera wrote:
 On Wed, Jan 21, 2009 at 6:37 PM, Jochem Maas joc...@iamjochem.com wrote:
  Chris schreef:
 
  Yea if you're only targeting 1 db, then why not use that class?  At
  least then there's the php manual to figure out what something does.
  Because then to add query logging for the whole app, you just need to
  put it
  in the class :)
 
  (I've done that before to check what's being run and where from,
  comes in
  very handy).
 
 
 
  That's done by tail -f /var/log/mysql/query.log. :D
 
  That won't tell you where a query comes from ;) Add a debug_backtrace
  into the class to also pinpoint where the query was called from.
  Complicated queries built on variables (or even just long queries built
  over multiple lines) will be hard to find just by looking at the mysql
  query log.
 
 
  besides on shared hosting that log is often turned off even if you can get 
  at it.
 
 
 
 That's why I set up a local dev environment.  If something is wrong,
 just grab a db dump  figure it out locally.  That way I can do
 whatever I need to really try out what the issue is and the best way
 to resolve it.
 
 Just merely saying how I develop.  Whatever gets it done is the real way. :)
 
A DB dump won't always tell you where the problem lies. With proper
logging, you can use the DB dump to work out what went wrong precisely.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] MySQL class. Thoughts?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 7:07 PM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Wed, 2009-01-21 at 18:52 -0500, Eric Butera wrote:
 On Wed, Jan 21, 2009 at 6:37 PM, Jochem Maas joc...@iamjochem.com wrote:
  Chris schreef:
 
  Yea if you're only targeting 1 db, then why not use that class?  At
  least then there's the php manual to figure out what something does.
  Because then to add query logging for the whole app, you just need to
  put it
  in the class :)
 
  (I've done that before to check what's being run and where from,
  comes in
  very handy).
 
 
 
  That's done by tail -f /var/log/mysql/query.log. :D
 
  That won't tell you where a query comes from ;) Add a debug_backtrace
  into the class to also pinpoint where the query was called from.
  Complicated queries built on variables (or even just long queries built
  over multiple lines) will be hard to find just by looking at the mysql
  query log.
 
 
  besides on shared hosting that log is often turned off even if you can get 
  at it.
 
 

 That's why I set up a local dev environment.  If something is wrong,
 just grab a db dump  figure it out locally.  That way I can do
 whatever I need to really try out what the issue is and the best way
 to resolve it.

 Just merely saying how I develop.  Whatever gets it done is the real way. :)

 A DB dump won't always tell you where the problem lies. With proper
 logging, you can use the DB dump to work out what went wrong precisely.


 Ash
 www.ashleysheridan.co.uk



I meant grab a remote db dump, import it locally, reproduce the issue
locally, look at local query log, fix.

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



[PHP] Help me understand unit testing?

2009-01-21 Thread Murray
Hi All,

I'd like to understand unit testing better (or, in fact, at all). I
understand the broad idea that testing Is A Very Good Thing, but when I have
tried to look into it further (for example, have just been looking through
the PHPUnit site), I always end up thinking 'This looks like more trouble
than it's worth.' I'm sure that's down to me and not the process of unit
testing, but I'd like to get some idea of how people on the list actually
use unit testing in the real world.

I'm assuming that you have your actual application classes and functions
designed in their own files, and then you build a series of unit testing
classes / functions in their own sort of space, but do you build these in
parallel to your application code, or during alpha / beta testing etc?

Any practical or even theoretical advice welcome!

Many thanks,

M is for Murray


Re: [PHP] Help me understand unit testing?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 7:01 PM, Murray planetthought...@gmail.com wrote:
 Hi All,

 I'd like to understand unit testing better (or, in fact, at all). I
 understand the broad idea that testing Is A Very Good Thing, but when I have
 tried to look into it further (for example, have just been looking through
 the PHPUnit site), I always end up thinking 'This looks like more trouble
 than it's worth.' I'm sure that's down to me and not the process of unit
 testing, but I'd like to get some idea of how people on the list actually
 use unit testing in the real world.

 I'm assuming that you have your actual application classes and functions
 designed in their own files, and then you build a series of unit testing
 classes / functions in their own sort of space, but do you build these in
 parallel to your application code, or during alpha / beta testing etc?

 Any practical or even theoretical advice welcome!

 Many thanks,

 M is for Murray


Well this was a hard topic for me to grasp too.  A lot of times I
still get lazy about it, but I strive to do my best.  Unit testing
makes sure your code works as expected.  So if you're messing around
with stuff, keep re-running your test suite and see if your changes
break any of your tests.  This way you know whether or not your
changes are breaking the very apps that rely on your code.

Unit testing also allows you to quickly assess problems with different
servers, php upgrades, whatever.

Of course these are just little points.  Just give it a try and keep
going at it.  Once I started I noticed that I had been writing my code
all wrong.  Lots of weird dependencies, reliance on hard to recreate
state, stuff like that.  It helped me to start writing leaner methods
that targeted what they were supposed to do a lot better.

There's a lot of info on this subject all across the net  in books.
It isn't just limited to php, but programming in general.

V is for Vendetta?

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



Re: [PHP] Help me understand unit testing?

2009-01-21 Thread Murray
I think this is my problem -- basically to know how to get some benefit from
it.

If I have a function in a class that is supposed to return some rows, how
would I go about performing a useful unit test on it? In theory (and in my
current practice), I can simply dump the array or object, or step through
the code with XDebug in Netbeans PHP (love this app!) to see what is taking
place.

Where would a unit test come into this process in a useful way? Is it
because I can abstract the call to that function / class without having code
that puts it to the page? Some other benefit?

M is for Murray


On Thu, Jan 22, 2009 at 10:13 AM, Eric Butera eric.but...@gmail.com wrote:

 On Wed, Jan 21, 2009 at 7:01 PM, Murray planetthought...@gmail.com
 wrote:
  Hi All,
 
  I'd like to understand unit testing better (or, in fact, at all). I
  understand the broad idea that testing Is A Very Good Thing, but when I
 have
  tried to look into it further (for example, have just been looking
 through
  the PHPUnit site), I always end up thinking 'This looks like more trouble
  than it's worth.' I'm sure that's down to me and not the process of unit
  testing, but I'd like to get some idea of how people on the list actually
  use unit testing in the real world.
 
  I'm assuming that you have your actual application classes and functions
  designed in their own files, and then you build a series of unit testing
  classes / functions in their own sort of space, but do you build these in
  parallel to your application code, or during alpha / beta testing etc?
 
  Any practical or even theoretical advice welcome!
 
  Many thanks,
 
  M is for Murray
 

 Well this was a hard topic for me to grasp too.  A lot of times I
 still get lazy about it, but I strive to do my best.  Unit testing
 makes sure your code works as expected.  So if you're messing around
 with stuff, keep re-running your test suite and see if your changes
 break any of your tests.  This way you know whether or not your
 changes are breaking the very apps that rely on your code.

 Unit testing also allows you to quickly assess problems with different
 servers, php upgrades, whatever.

 Of course these are just little points.  Just give it a try and keep
 going at it.  Once I started I noticed that I had been writing my code
 all wrong.  Lots of weird dependencies, reliance on hard to recreate
 state, stuff like that.  It helped me to start writing leaner methods
 that targeted what they were supposed to do a lot better.

 There's a lot of info on this subject all across the net  in books.
 It isn't just limited to php, but programming in general.

 V is for Vendetta?



Re: [PHP] Help me understand unit testing?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 7:24 PM, Murray planetthought...@gmail.com wrote:
 I think this is my problem -- basically to know how to get some benefit from
 it.

 If I have a function in a class that is supposed to return some rows, how
 would I go about performing a useful unit test on it? In theory (and in my
 current practice), I can simply dump the array or object, or step through
 the code with XDebug in Netbeans PHP (love this app!) to see what is taking
 place.

 Where would a unit test come into this process in a useful way? Is it
 because I can abstract the call to that function / class without having code
 that puts it to the page? Some other benefit?

 M is for Murray


 On Thu, Jan 22, 2009 at 10:13 AM, Eric Butera eric.but...@gmail.com wrote:

 On Wed, Jan 21, 2009 at 7:01 PM, Murray planetthought...@gmail.com
 wrote:
  Hi All,
 
  I'd like to understand unit testing better (or, in fact, at all). I
  understand the broad idea that testing Is A Very Good Thing, but when I
  have
  tried to look into it further (for example, have just been looking
  through
  the PHPUnit site), I always end up thinking 'This looks like more
  trouble
  than it's worth.' I'm sure that's down to me and not the process of unit
  testing, but I'd like to get some idea of how people on the list
  actually
  use unit testing in the real world.
 
  I'm assuming that you have your actual application classes and functions
  designed in their own files, and then you build a series of unit testing
  classes / functions in their own sort of space, but do you build these
  in
  parallel to your application code, or during alpha / beta testing etc?
 
  Any practical or even theoretical advice welcome!
 
  Many thanks,
 
  M is for Murray
 

 Well this was a hard topic for me to grasp too.  A lot of times I
 still get lazy about it, but I strive to do my best.  Unit testing
 makes sure your code works as expected.  So if you're messing around
 with stuff, keep re-running your test suite and see if your changes
 break any of your tests.  This way you know whether or not your
 changes are breaking the very apps that rely on your code.

 Unit testing also allows you to quickly assess problems with different
 servers, php upgrades, whatever.

 Of course these are just little points.  Just give it a try and keep
 going at it.  Once I started I noticed that I had been writing my code
 all wrong.  Lots of weird dependencies, reliance on hard to recreate
 state, stuff like that.  It helped me to start writing leaner methods
 that targeted what they were supposed to do a lot better.

 There's a lot of info on this subject all across the net  in books.
 It isn't just limited to php, but programming in general.

 V is for Vendetta?



Think of an ecommerce app.  You've got code that calculates price
based on lots of different factors.  Unit testing lets you make sure
that your prices will always add up correctly based on those factors.
Too many times have I messed something up and all of a sudden Michigan
tax isn't acting right.  Unit testing prevents those 4:50pm mistakes.
:D

Start small just testing the logic of your app.  Don't worry so much
about making sure a query has x data.  You can do something called
mock that out later on once you've got a better handle on things.

You might also look at established code and see their unit tests to
maybe get a better idea of how it is really useful.  Really tho

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



Re: [PHP] Help me understand unit testing?

2009-01-21 Thread Eric Butera
On Wed, Jan 21, 2009 at 7:31 PM, Eric Butera eric.but...@gmail.com wrote:
 On Wed, Jan 21, 2009 at 7:24 PM, Murray planetthought...@gmail.com wrote:
 I think this is my problem -- basically to know how to get some benefit from
 it.

 If I have a function in a class that is supposed to return some rows, how
 would I go about performing a useful unit test on it? In theory (and in my
 current practice), I can simply dump the array or object, or step through
 the code with XDebug in Netbeans PHP (love this app!) to see what is taking
 place.

 Where would a unit test come into this process in a useful way? Is it
 because I can abstract the call to that function / class without having code
 that puts it to the page? Some other benefit?

 M is for Murray


 On Thu, Jan 22, 2009 at 10:13 AM, Eric Butera eric.but...@gmail.com wrote:

 On Wed, Jan 21, 2009 at 7:01 PM, Murray planetthought...@gmail.com
 wrote:
  Hi All,
 
  I'd like to understand unit testing better (or, in fact, at all). I
  understand the broad idea that testing Is A Very Good Thing, but when I
  have
  tried to look into it further (for example, have just been looking
  through
  the PHPUnit site), I always end up thinking 'This looks like more
  trouble
  than it's worth.' I'm sure that's down to me and not the process of unit
  testing, but I'd like to get some idea of how people on the list
  actually
  use unit testing in the real world.
 
  I'm assuming that you have your actual application classes and functions
  designed in their own files, and then you build a series of unit testing
  classes / functions in their own sort of space, but do you build these
  in
  parallel to your application code, or during alpha / beta testing etc?
 
  Any practical or even theoretical advice welcome!
 
  Many thanks,
 
  M is for Murray
 

 Well this was a hard topic for me to grasp too.  A lot of times I
 still get lazy about it, but I strive to do my best.  Unit testing
 makes sure your code works as expected.  So if you're messing around
 with stuff, keep re-running your test suite and see if your changes
 break any of your tests.  This way you know whether or not your
 changes are breaking the very apps that rely on your code.

 Unit testing also allows you to quickly assess problems with different
 servers, php upgrades, whatever.

 Of course these are just little points.  Just give it a try and keep
 going at it.  Once I started I noticed that I had been writing my code
 all wrong.  Lots of weird dependencies, reliance on hard to recreate
 state, stuff like that.  It helped me to start writing leaner methods
 that targeted what they were supposed to do a lot better.

 There's a lot of info on this subject all across the net  in books.
 It isn't just limited to php, but programming in general.

 V is for Vendetta?



 Think of an ecommerce app.  You've got code that calculates price
 based on lots of different factors.  Unit testing lets you make sure
 that your prices will always add up correctly based on those factors.
 Too many times have I messed something up and all of a sudden Michigan
 tax isn't acting right.  Unit testing prevents those 4:50pm mistakes.
 :D

 Start small just testing the logic of your app.  Don't worry so much
 about making sure a query has x data.  You can do something called
 mock that out later on once you've got a better handle on things.

 You might also look at established code and see their unit tests to
 maybe get a better idea of how it is really useful.  Really tho


oops I accidentally sent that before finishing.  But you get the idea
at any rate.

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



Re: [PHP] Code Not entering the value in the Database

2009-01-21 Thread Murray
You don't appear to be doing anything with this line of your code. You build
a string variable, but you don't call anything like mysql_query($sql) to
actually execute the INSERT statement.

M is for Murray


On Wed, Jan 21, 2009 at 12:34 AM, Chris Carter chandan9sha...@yahoo.comwrote:

 $sql = insert into `userstable` (hiddendata) VALUES ('$hiddendata');



[PHP] distinguish between null variable and unset variable

2009-01-21 Thread Jack Bates
How can I tell the difference between a variable whose value is null and
a variable which is not set?

// cannot use === null:

ket% php -r '$null = null; var_dump(null === $null);'
bool(true)
ket% php -r 'var_dump(null === $unset);' 
bool(true)
ket% 

// - cannot use isset() either:

ket% php -r '$null = null; var_dump(isset($null));'   
bool(false)
ket% php -r 'var_dump(isset($unset));'   
bool(false)
ket% 


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



Re: [PHP] distinguish between null variable and unset variable

2009-01-21 Thread Daniel Brown
On Wed, Jan 21, 2009 at 20:27, Jack Bates ms...@freezone.co.uk wrote:
 How can I tell the difference between a variable whose value is null and
 a variable which is not set?

Unfortunately, in PHP - like other languages - you can't.

A variable is considered to be null if:
* it has been assigned the constant NULL.
* it has not been set to any value yet.
* it has been unset().

-- 
/Daniel P. Brown
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Unadvertised dedicated server deals, too low to print - email me to find out!

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



Re: [PHP] distinguish between null variable and unset variable

2009-01-21 Thread Paul M Foster
On Wed, Jan 21, 2009 at 05:27:35PM -0800, Jack Bates wrote:

 How can I tell the difference between a variable whose value is null and
 a variable which is not set?
 
 // cannot use === null:
 
 ket% php -r '$null = null; var_dump(null === $null);'
 bool(true)
 ket% php -r 'var_dump(null === $unset);'
 bool(true)
 ket%
 
 // - cannot use isset() either:
 
 ket% php -r '$null = null; var_dump(isset($null));'
 bool(false)
 ket% php -r 'var_dump(isset($unset));'
 bool(false)
 ket%

Oh I *love* this problem. I still haven't found the perfect solution for
it. But since a lot of things in PHP float around as strings, I often
use strlen(trim($var)) == 0 to determine the emptiness of a variable.
But it all depends on what type of variable you expect to receive. I
don't have this problem so much with methods and functions, since I
specifically engineer them to give me exact results. But I get it when
testing POST and GET variables from web pages.

Paul

-- 
Paul M. Foster

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



Re: [PHP] distinguish between null variable and unset variable

2009-01-21 Thread Alexandre Gaigalas
On Thu, Jan 22, 2009 at 12:21 AM, Paul M Foster pa...@quillandmouse.comwrote:

 On Wed, Jan 21, 2009 at 05:27:35PM -0800, Jack Bates wrote:

  How can I tell the difference between a variable whose value is null and
  a variable which is not set?
 
  // cannot use === null:
 
  ket% php -r '$null = null; var_dump(null === $null);'
  bool(true)
  ket% php -r 'var_dump(null === $unset);'
  bool(true)
  ket%
 
  // - cannot use isset() either:
 
  ket% php -r '$null = null; var_dump(isset($null));'
  bool(false)
  ket% php -r 'var_dump(isset($unset));'
  bool(false)
  ket%

 Oh I *love* this problem. I still haven't found the perfect solution for
 it. But since a lot of things in PHP float around as strings, I often
 use strlen(trim($var)) == 0 to determine the emptiness of a variable.
 But it all depends on what type of variable you expect to receive. I
 don't have this problem so much with methods and functions, since I
 specifically engineer them to give me exact results. But I get it when
 testing POST and GET variables from web pages.

 Paul

 --
 Paul M. Foster


I've replaced all my techniques for testing POST and GET data by the filter
extension.

http://php.net/filter

-- 
Alexandre Gomes Gaigalas
alexan...@gaigalas.net
http://Alexandre.Gaigalas.Net


Re: [PHP] distinguish between null variable and unset variable

2009-01-21 Thread Lars Torben Wilson
2009/1/21 Daniel Brown danbr...@php.net:
 On Wed, Jan 21, 2009 at 20:27, Jack Bates ms...@freezone.co.uk wrote:
 How can I tell the difference between a variable whose value is null and
 a variable which is not set?

Unfortunately, in PHP - like other languages - you can't.

A variable is considered to be null if:
* it has been assigned the constant NULL.
* it has not been set to any value yet.
* it has been unset().

Actually, you can, but it's not terribly pretty. Check for the
variable name as a key in the array returned from get_defined_vars():

?php

$foo = 0;
$bar = null;

$variables = get_defined_vars();

// Check for $foo, $bar, and $baz:
foreach (array('foo', 'bar', 'baz') as $var) {
if (!array_key_exists($var, $variables)) {
echo \$$var does not exist in the current scope.\n;
continue;
}
if (is_null($$var)) {
echo \$$var exists and is null in the current scope.\n;
continue;
}
echo \$$var exists and is not null in the current scope.\n;
}

?

Again, not that pretty, and it only checks the local scope, but it can be done.


Regards,

Torben

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



RE: [PHP] Please explain: index.php/index/index

2009-01-21 Thread leledumbo


Boyd, Todd M. wrote:
 
 IIRF - Ionics ISAPI Rewrite Filter [1] is totally free... and it
 supports the use of Regular Expressions [2] in your rewrite rules. If
 you're going to use any sort of MVC-based URLs in IIS, this library is a
 must-have.
 
Thanks for the link, I'll try it tonight.
-- 
View this message in context: 
http://www.nabble.com/Please-explain%3A-index.php-index-index-tp21578728p21598988.html
Sent from the PHP - General mailing list archive at Nabble.com.


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