php-general Digest 5 Oct 2006 07:30:33 -0000 Issue 4384

Topics (messages 242617 through 242637):

Re: PHP jump to other page
        242617 by: João Cândido de Souza Neto
        242627 by: Penthexquadium

Re: File Uploads not working over SSL
        242618 by: João Cândido de Souza Neto
        242619 by: Rahul S. Johari
        242620 by: Rahul S. Johari

quick question about preg_replace
        242621 by: Martin Bach Nielsen
        242629 by: Penthexquadium

Re: WebMail client
        242622 by: Christopher Weldon
        242628 by: Glenn Richmond
        242634 by: Google Kreme

Re: file to blob
        242623 by: Curt Zirzow

Really  strange
        242624 by: Deckard
        242625 by: Ben Ramsey

Re: Really  strange / TYPO
        242626 by: Deckard
        242630 by: Ben Ramsey
        242632 by: Deckard

Help on objects
        242631 by: Deckard
        242633 by: Penthexquadium
        242636 by: Satyam

Re: OOP Hello World
        242635 by: Martin Alterisio

÷ÏÐÒÏÓ.
        242637 by: Nikolay Furletov

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
In other hand, if you sent any character yet, you can use.

IF (statement == TRUE)
    stay on this page, index.php
ELSE
   echo "<script language=\"javascript\">window 
location=\"index2.php\";</script>";


""AraDaen"" <[EMAIL PROTECTED]> escreveu na mensagem 
news:[EMAIL PROTECTED]
> If you have not sent any character till that moment, you can use:
>
> IF (statement == TRUE)
>   { stay on this page, index.php }
> ELSE {
> header("Location: index2.php");
>
>
>
>
> cya 

--- End Message ---
--- Begin Message ---
On Thu, 5 Oct 2006 01:17:41 +0700, Groundhog <[EMAIL PROTECTED]> wrote:

> how can I jump to another page after IF..ELSE statement, for example:
> 
> IF (statement == TRUE)
>    { stay on this page, index.php }
> ELSE { jump to index2.php}
> 
> -- 
> Come and Visit My Blog
> http://ubuntu-ku.blogspot.com
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

if (!statement) {
    header('Location: index2.php');
    exit;
}
// other codes...

--- End Message ---
--- Begin Message ---
Please, show us your code.

""Rahul S. Johari"" <[EMAIL PROTECTED]> escreveu na mensagem 
news:[EMAIL PROTECTED]
Ave,

I have a File Manager application in place for over 2 years now.
Everything¹s been working groovy!
Until yesterday. Yesterday we purchased and installed an SSL Certificate.
And now the uploads are not working anymore! Gets the ³Page cannot be
displayed² error. Tried the same application without SSL and it¹s working
fine!

What¹s the workaround? How do I get this to work on SSL?
Any suggestions?

Rahul S. Johari
Supervisor, Internet & Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

--- End Message ---
--- Begin Message ---
Well, the File Manager application itself is pretty extensive... But if
you're looking for the upload code, here it is (sensitive information
erased):

                            if($upload_file) {
                            $db = mysql_connect("localhost","usr","pwd");
                            mysql_select_db("db",$db);
                            $date = date("m-d-Y, D, H:i");
                            $img1_name = str_replace("\'", null,
$img1_name);
                            if(($img1_name=="") || ($img1_size<=10)) {
                            ?>
                            <script
language="javascript">alert('error');</script>
                            <?
                            }
                            else {

                    $justchecking = "imsafm/$location/$img1_name";
                    if (file_exists($justchecking)) {
                    echo "<i>$img1_name</i> already exists. Please delete
the file first, or rename the file before uploading.";
                    }
                   
                    else {
                    $sql = "INSERT INTO file
(login,filename,descr,size,uppedby,date) VALUES
('$location','$img1_name','$desc','$img1_size','$PHP_login','$date')";
                    $result = mysql_query($sql) or die("There is a
problem.");
                    copy("$img1", "imsafm/$location/$img1_name") or
die("Could not do");
                    }
                }


And this is what I have as the <form> tag for the upload form. The form
itself is pretty simple & basic, so nothing much to show in it:
<form method="post" action="http://www.myurl.com/imsafm2_main.php";
name="upload_form" enctype="multipart/form-data">

Thanks.

On 10/4/06 3:49 PM, "João Cândido de Souza Neto"
<[EMAIL PROTECTED]> wrote:

> Please, show us your code.
> 
> ""Rahul S. Johari"" <[EMAIL PROTECTED]> escreveu na mensagem
> news:[EMAIL PROTECTED]
> Ave,
> 
> I have a File Manager application in place for over 2 years now.
> Everything¹s been working groovy!
> Until yesterday. Yesterday we purchased and installed an SSL Certificate.
> And now the uploads are not working anymore! Gets the ³Page cannot be
> displayed² error. Tried the same application without SSL and it¹s working
> fine!
> 
> What¹s the workaround? How do I get this to work on SSL?
> Any suggestions?
> 
> Rahul S. Johari
> Supervisor, Internet & Administration
> Informed Marketing Services Inc.
> 500 Federal Street, Suite 201
> Troy NY 12180
> 
> Tel: (518) 687-6700 x154
> Fax: (518) 687-6799
> Email: [EMAIL PROTECTED]
> http://www.informed-sources.com

Rahul S. Johari
Supervisor, Internet & Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com


--- End Message ---
--- Begin Message ---
Sorry, copied wrong code to you. Actually code has https in it:
<form method="post" action="https://www.myurl.com/imsafm2_main.php";
name="upload_form" enctype="multipart/form-data"



On 10/4/06 4:55 PM, "Andrew Brampton" <[EMAIL PROTECTED]> wrote:

> <form method="post" action="http://www.myurl.com/imsafm2_main.php";
> name="upload_form" enctype="multipart/form-data">
> 
> 
> might be your error, should that not be https://   ?
> 
> Andrew
> 
> ----- Original Message -----
> From: "Rahul S. Johari" <[EMAIL PROTECTED]>
> To: "Jo ã o C â ndido de Souza Neto" <[EMAIL PROTECTED]>; "PHP"
> <[email protected]>
> Sent: Wednesday, October 04, 2006 9:02 PM
> Subject: Re: [PHP] File Uploads not working over SSL
> 
> 
> 
> Well, the File Manager application itself is pretty extensive... But if
> you're looking for the upload code, here it is (sensitive information
> erased):
> 
>                             if($upload_file) {
>                             $db = mysql_connect("localhost","usr","pwd");
>                             mysql_select_db("db",$db);
>                             $date = date("m-d-Y, D, H:i");
>                             $img1_name = str_replace("\'", null,
> $img1_name);
>                             if(($img1_name=="") || ($img1_size<=10)) {
>                             ?>
>                             <script
> language="javascript">alert('error');</script>
>                             <?
>                             }
>                             else {
> 
>                     $justchecking = "imsafm/$location/$img1_name";
>                     if (file_exists($justchecking)) {
>                     echo "<i>$img1_name</i> already exists. Please delete
> the file first, or rename the file before uploading.";
>                     }
> 
>                     else {
>                     $sql = "INSERT INTO file
> (login,filename,descr,size,uppedby,date) VALUES
> ('$location','$img1_name','$desc','$img1_size','$PHP_login','$date')";
>                     $result = mysql_query($sql) or die("There is a
> problem.");
>                     copy("$img1", "imsafm/$location/$img1_name") or
> die("Could not do");
>                     }
>                 }
> 
> 
> And this is what I have as the <form> tag for the upload form. The form
> itself is pretty simple & basic, so nothing much to show in it:
> <form method="post" action="http://www.myurl.com/imsafm2_main.php";
> name="upload_form" enctype="multipart/form-data">
> 
> Thanks.
> 
> On 10/4/06 3:49 PM, "João Cândido de Souza Neto"
> <[EMAIL PROTECTED]> wrote:
> 
>> Please, show us your code.
>> 
>> ""Rahul S. Johari"" <[EMAIL PROTECTED]> escreveu na mensagem
>> news:[EMAIL PROTECTED]
>> Ave,
>> 
>> I have a File Manager application in place for over 2 years now.
>> Everything¹s been working groovy!
>> Until yesterday. Yesterday we purchased and installed an SSL Certificate.
>> And now the uploads are not working anymore! Gets the ³Page cannot be
>> displayed² error. Tried the same application without SSL and it¹s working
>> fine!
>> 
>> What¹s the workaround? How do I get this to work on SSL?
>> Any suggestions?
>> 
>> Rahul S. Johari
>> Supervisor, Internet & Administration
>> Informed Marketing Services Inc.
>> 500 Federal Street, Suite 201
>> Troy NY 12180
>> 
>> Tel: (518) 687-6700 x154
>> Fax: (518) 687-6799
>> Email: [EMAIL PROTECTED]
>> http://www.informed-sources.com
> 
> Rahul S. Johari
> Supervisor, Internet & Administration
> Informed Marketing Services Inc.
> 500 Federal Street, Suite 201
> Troy NY 12180
> 
> Tel: (518) 687-6700 x154
> Fax: (518) 687-6799
> Email: [EMAIL PROTECTED]
> http://www.informed-sources.com
> 

Rahul S. Johari
Supervisor, Internet & Administration
Informed Marketing Services Inc.
500 Federal Street, Suite 201
Troy NY 12180

Tel: (518) 687-6700 x154
Fax: (518) 687-6799
Email: [EMAIL PROTECTED]
http://www.informed-sources.com

--- End Message ---
--- Begin Message ---
Hi all.

 

I have written a guestbook (I know, there's a ton out there), which until
recently did not get any spam, so now I'm trying to remove the spam-ad by
using preg_replace:

 

$melding = preg_replace('/(<a href=\"http:\/\/[^^]+)/i', "This message is
temporarily cut-off due to spam-suspicion.", $melding);

 

However, this only makes the problem half-solved, since I also want any text
before the link to be replaced with a message as stated above. The above
line removes anything after '<a href=//'.

Is there any way to make the above line to include anything before the <a
href=// ?

 

I have tried different options, and yes, I have read the php manual on
preg_replace, but I might not have properly identified how to get the text
in front modified.

 

Thankful for any hints, tips, links, anything that helps :-)

 

Regards,

Martin Bach Nielsen 


--- End Message ---
--- Begin Message ---
On Wed, 4 Oct 2006 23:19:58 +0200, "Martin Bach Nielsen" <[EMAIL PROTECTED]> 
wrote:

> Hi all.
> 
>  
> 
> I have written a guestbook (I know, there's a ton out there), which until
> recently did not get any spam, so now I'm trying to remove the spam-ad by
> using preg_replace:
> 
>  
> 
> $melding = preg_replace('/(<a href=\"http:\/\/[^^]+)/i', "This message is
> temporarily cut-off due to spam-suspicion.", $melding);
> 
>  
> 
> However, this only makes the problem half-solved, since I also want any text
> before the link to be replaced with a message as stated above. The above
> line removes anything after '<a href=//'.
> 
> Is there any way to make the above line to include anything before the <a
> href=// ?
> 
>  
> 
> I have tried different options, and yes, I have read the php manual on
> preg_replace, but I might not have properly identified how to get the text
> in front modified.
> 
>  
> 
> Thankful for any hints, tips, links, anything that helps :-)
> 
>  
> 
> Regards,
> 
> Martin Bach Nielsen 
> 

If you only want to replace the line including url(s) by a message, a
simple regular expression is enough.

<?php
$melding = "This is a spam.\n"
         . "This is a <a href=\"http://www.example.com/\";>example</a> line.\n"
         . "Another line.\n"
         . "<a href=\"http://www.e.com/ads/show?n=123\";>123</a> (456)\n"
         . "End Line.\n";

$melding = preg_replace("/.*?<a href=\"http:\/\/.+/i", "<This line is 
temporarily cut-off due to spam-suspicion.>", $melding);

echo $melding;
?>

The script above will output:

This is a spam.
<This line is temporarily cut-off due to spam-suspicion.>
Another line.
<This line is temporarily cut-off due to spam-suspicion.>
End Line.

-- 
Sorry for my poor English.

--- End Message ---
--- Begin Message ---
Peter Lauri wrote:
> Hi,
> 
>  
> 
> Do you have any suggestion on WebMail clients written in PHP that is good
> and easy to install?
> 

http://hastymail.sourceforge.net/

--
Christopher Weldon

--- End Message ---
--- Begin Message ---
http://www.roundcube.net/

I can't say enough good things about the roundcube project. Ajax-based,
like a desktop email client in a browser. Still got some minor bugs, but
works pretty well. Note that it's still a Beta at this point.

Cheers,

Glenn.

Christopher Weldon wrote:
> Peter Lauri wrote:
>   
>> Hi,
>>
>>  
>>
>> Do you have any suggestion on WebMail clients written in PHP that is good
>> and easy to install?
>>
>>     
>
> http://hastymail.sourceforge.net/
>
> --
> Christopher Weldon
>
>   

--- End Message ---
--- Begin Message ---
On 04 Oct 2006, at 19:28 , Glenn Richmond wrote:
http://www.roundcube.net/

I can't say enough good things about the roundcube project. Ajax- based, like a desktop email client in a browser. Still got some minor bugs, but
works pretty well. Note that it's still a Beta at this point.

Despite it being beta, and rather an early beta at that, I've found roundcube to work amazingly well. less features than Squirrelmail, but sooo much faster.

I'm super impressed.

--
My little brother got his arm stuck in the microwave. So my mom had to take him to the hospital. My grandma dropped acid this morning, and she freaked out. She hijacked a busload of penguins. So it's sort of a family crisis. Bye!
--- End Message ---
--- Begin Message ---
On 10/4/06, Manuel Lemos <[EMAIL PROTECTED]> wrote:
Hello,

Sorry, I sent the message too soon. The HTTP client class is here:

http://www.phpclasses.org/httpclient


I'm wondering how soap has to do with this.

Curt

--- End Message ---
--- Begin Message ---
Hi,

I have this line of code:
include_once('../config.inc.php');

I'm 100% sure that the file config.inc.php is a directory up.

config.inc.php is in /var/www/html
and the file that calls it is in
/var/www/html/classes

nevertheless, i'm getting the error:
"Warning: main(../config.inc): failed to open stream: No such file or
directory in /var/www/html/classes/dBInsert.php on line 10

Warning: main(): Failed opening '../config.inc' for inclusion
(include_path='.:/usr/share/pear') in /var/www/html/classes/dBInsert.php
on line 10"

I'm boggled!

Any help would be appreciated.

Best Regards,
Deckard

--- End Message ---
--- Begin Message ---
On 10/4/06 8:32 PM, Deckard wrote:
Hi,

I have this line of code:
include_once('../config.inc.php');

I'm 100% sure that the file config.inc.php is a directory up.

config.inc.php is in /var/www/html
and the file that calls it is in
/var/www/html/classes

nevertheless, i'm getting the error:
"Warning: main(../config.inc): failed to open stream: No such file or
directory in /var/www/html/classes/dBInsert.php on line 10

Warning: main(): Failed opening '../config.inc' for inclusion
(include_path='.:/usr/share/pear') in /var/www/html/classes/dBInsert.php
on line 10"

The first thing that jumps out at me is that your error says it failed to open ../config.inc, but you say the file is named config.inc.php. Check your code to ensure that you have:

include_once('../config.inc.php');

and not:

include_once('../config.inc');

If config.inc.php is the correct file you want to include and you're trying to include config.inc, then it obviously can't find it because it doesn't exist. :-)

--
Ben Ramsey
http://benramsey.com/

--- End Message ---
--- Begin Message ---
Hi,

It's a typo.
The file is really config.inc.php everywhere

Regards,
Deckard

Ben Ramsey wrote:
> On 10/4/06 8:32 PM, Deckard wrote:
>> Hi,
>>
>> I have this line of code:
>> include_once('../config.inc.php');
>>
>> I'm 100% sure that the file config.inc.php is a directory up.
>>
>> config.inc.php is in /var/www/html
>> and the file that calls it is in
>> /var/www/html/classes
>>
>> nevertheless, i'm getting the error:
>> "Warning: main(../config.inc): failed to open stream: No such file or
>> directory in /var/www/html/classes/dBInsert.php on line 10
>>
>> Warning: main(): Failed opening '../config.inc' for inclusion
>> (include_path='.:/usr/share/pear') in /var/www/html/classes/dBInsert.php
>> on line 10"
> 
> The first thing that jumps out at me is that your error says it failed
> to open ../config.inc, but you say the file is named config.inc.php.
> Check your code to ensure that you have:
> 
> include_once('../config.inc.php');
> 
> and not:
> 
> include_once('../config.inc');
> 
> If config.inc.php is the correct file you want to include and you're
> trying to include config.inc, then it obviously can't find it because it
> doesn't exist. :-)
> 

--- End Message ---
--- Begin Message ---
On 10/4/06 9:14 PM, Deckard wrote:
It's a typo.
The file is really config.inc.php everywhere

Check the file permissions. Does the Webserver have permission to read from the /var/www/html (it probably does, but it wouldn't hurt to check)? Does the Web server have permission to read /var/www/html/config.inc.php? Do you happen to have PHP running in safe_mode? If so, is the owner of /var/www/html/classes/dBInsert.php the same owner of /var/www/html/config.inc.php?

These are just the things I can think of off the top of my head that would block your script from being able to include a file one directory above it.


Ben Ramsey wrote:
On 10/4/06 8:32 PM, Deckard wrote:
Hi,

I have this line of code:
include_once('../config.inc.php');

I'm 100% sure that the file config.inc.php is a directory up.

config.inc.php is in /var/www/html
and the file that calls it is in
/var/www/html/classes

nevertheless, i'm getting the error:
"Warning: main(../config.inc): failed to open stream: No such file or
directory in /var/www/html/classes/dBInsert.php on line 10

Warning: main(): Failed opening '../config.inc' for inclusion
(include_path='.:/usr/share/pear') in /var/www/html/classes/dBInsert.php
on line 10"
The first thing that jumps out at me is that your error says it failed
to open ../config.inc, but you say the file is named config.inc.php.
Check your code to ensure that you have:

include_once('../config.inc.php');

and not:

include_once('../config.inc');

If config.inc.php is the correct file you want to include and you're
trying to include config.inc, then it obviously can't find it because it
doesn't exist. :-)



--
Ben Ramsey
http://benramsey.com/

--- End Message ---
--- Begin Message ---
Yes, permissions are fine :(

Ben Ramsey wrote:
> On 10/4/06 9:14 PM, Deckard wrote:
>> It's a typo.
>> The file is really config.inc.php everywhere
> 
> Check the file permissions. Does the Webserver have permission to read
> from the /var/www/html (it probably does, but it wouldn't hurt to
> check)? Does the Web server have permission to read
> /var/www/html/config.inc.php? Do you happen to have PHP running in
> safe_mode? If so, is the owner of /var/www/html/classes/dBInsert.php the
> same owner of /var/www/html/config.inc.php?
> 
> These are just the things I can think of off the top of my head that
> would block your script from being able to include a file one directory
> above it.
> 
>>
>> Ben Ramsey wrote:
>>> On 10/4/06 8:32 PM, Deckard wrote:
>>>> Hi,
>>>>
>>>> I have this line of code:
>>>> include_once('../config.inc.php');
>>>>
>>>> I'm 100% sure that the file config.inc.php is a directory up.
>>>>
>>>> config.inc.php is in /var/www/html
>>>> and the file that calls it is in
>>>> /var/www/html/classes
>>>>
>>>> nevertheless, i'm getting the error:
>>>> "Warning: main(../config.inc): failed to open stream: No such file or
>>>> directory in /var/www/html/classes/dBInsert.php on line 10
>>>>
>>>> Warning: main(): Failed opening '../config.inc' for inclusion
>>>> (include_path='.:/usr/share/pear') in
>>>> /var/www/html/classes/dBInsert.php
>>>> on line 10"
>>> The first thing that jumps out at me is that your error says it failed
>>> to open ../config.inc, but you say the file is named config.inc.php.
>>> Check your code to ensure that you have:
>>>
>>> include_once('../config.inc.php');
>>>
>>> and not:
>>>
>>> include_once('../config.inc');
>>>
>>> If config.inc.php is the correct file you want to include and you're
>>> trying to include config.inc, then it obviously can't find it because it
>>> doesn't exist. :-)
>>>
> 
> 

--- End Message ---
--- Begin Message ---
Hi,

I'm trying to lay my hands on PHP OOP, but it's not easy :(
I've read several examples in the web, but cannot transpose to may case.

I'm trying to set a class to make SQL inserts in mysql.

I have the class:
---------------------------------------------------------
<?php

  class dBInsert
 {
  // global variables
  var $first;
        
 // constructor
 function dBInsert($table, $sql)
 {
  $this->table = $table;
  $this->sql   = $sql;
                
  return(TRUE);         
 }


  // function that constructs the sql and inserts it into the database
  function InsertDB($sql)
   {

    print($sql);
    // connect to MySQL
    $conn->debug=1;
    $conn = &ADONewConnection('mysql');
    $conn->PConnect('localhost', 'deckard', 'ble', 'wordlife');
        
        if ($conn->Execute($sql) === false)
        print 'error inserting: '.$conn->ErrorMsg().'<BR>';
                        
        return (TRUE);
   }
}
--------------------------------------------------------------------

and the code that calls it:
--------------------------------------------------------------------
<?php

 include_once("classes/dBInsert.php");
 $sql = "INSERT INTO wl_admins VALUES ('',2)";
 $dBInsert = new dBInsert('wl_admins', '$sql');
 $dBInsert->InsertDB('$sql');

?>
--------------------------------------------------------------------

but it's not working ?

Can anyone give me a hand here ?

I've read the manuals, examples, etc.

Any help would be appreciated.

Best Regards,
Deckard

--- End Message ---
--- Begin Message ---
On Thu, 05 Oct 2006 02:47:59 +0100, Deckard <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I'm trying to lay my hands on PHP OOP, but it's not easy :(
> I've read several examples in the web, but cannot transpose to may case.
> 
> I'm trying to set a class to make SQL inserts in mysql.
> 
> I have the class:
> ---------------------------------------------------------
> <?php
> 
>   class dBInsert
>  {
>   // global variables
>   var $first;
>       
>  // constructor
>  function dBInsert($table, $sql)
>  {
>   $this->table = $table;
>   $this->sql   = $sql;
>               
>   return(TRUE);               
>  }
> 
> 
>   // function that constructs the sql and inserts it into the database
>   function InsertDB($sql)
>    {
> 
>     print($sql);
>     // connect to MySQL
>     $conn->debug=1;
>     $conn = &ADONewConnection('mysql');
>     $conn->PConnect('localhost', 'deckard', 'ble', 'wordlife');
>       
>       if ($conn->Execute($sql) === false)
>       print 'error inserting: '.$conn->ErrorMsg().'<BR>';
>                       
>       return (TRUE);
>    }
> }
> --------------------------------------------------------------------
> 
> and the code that calls it:
> --------------------------------------------------------------------
> <?php
> 
>  include_once("classes/dBInsert.php");
>  $sql = "INSERT INTO wl_admins VALUES ('',2)";
>  $dBInsert = new dBInsert('wl_admins', '$sql');
>  $dBInsert->InsertDB('$sql');
> 
> ?>
> --------------------------------------------------------------------
> 
> but it's not working ?
> 
> Can anyone give me a hand here ?
> 
> I've read the manuals, examples, etc.
> 
> Any help would be appreciated.
> 
> Best Regards,
> Deckard
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

You'd better learn the basic knowledge of PHP. There are several obvious
mistakes in your code.

> $dBInsert = new dBInsert('wl_admins', '$sql');
> $dBInsert->InsertDB('$sql');
Note that variables will *not* be expanded when they occur in single
quoted strings.

> $this->table = $table;
> $this->sql   = $sql;
The two variables seemed useless.

> $conn->debug=1;
> $conn = &ADONewConnection('mysql');
Called $conn before creating it.

And, I could not to know what is the purpose of this class.

PS, a description such as "it's not working" is useless for solving the
problem.

-- 
Sorry for my poor English.

--- End Message ---
--- Begin Message --- I've seen you already had a good answer on the errors in the code so I won't go on that. As for OOP, the one design error you have is that you are asking for an action, not an object. You want to make SQL inserts, that is your purpose, and that is an action, which is solved by a statement, not by an object. There is no doer. Objects are what even your English teacher would call objects while describing a sentence. You are asking for a verb, you don't have a subject, you don't have an object. Of course you can wrap an action in a class, but that is bad design. Classes will usually have names representing nouns, methods will be verbs, properties adjectives, more or less, that's OOP for English teachers.

Satyam

----- Original Message ----- From: "Deckard" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, October 05, 2006 3:47 AM
Subject: [PHP] Help on objects


Hi,

I'm trying to lay my hands on PHP OOP, but it's not easy :(
I've read several examples in the web, but cannot transpose to may case.

I'm trying to set a class to make SQL inserts in mysql.

I have the class:
---------------------------------------------------------
<?php

 class dBInsert
{
 // global variables
 var $first;

// constructor
function dBInsert($table, $sql)
{
 $this->table = $table;
 $this->sql   = $sql;

 return(TRUE);
}


 // function that constructs the sql and inserts it into the database
 function InsertDB($sql)
  {

   print($sql);
   // connect to MySQL
   $conn->debug=1;
   $conn = &ADONewConnection('mysql');
   $conn->PConnect('localhost', 'deckard', 'ble', 'wordlife');

if ($conn->Execute($sql) === false)
print 'error inserting: '.$conn->ErrorMsg().'<BR>';

return (TRUE);
  }
}
--------------------------------------------------------------------

and the code that calls it:
--------------------------------------------------------------------
<?php

include_once("classes/dBInsert.php");
$sql = "INSERT INTO wl_admins VALUES ('',2)";
$dBInsert = new dBInsert('wl_admins', '$sql');
$dBInsert->InsertDB('$sql');

?>
--------------------------------------------------------------------

but it's not working ?

Can anyone give me a hand here ?

I've read the manuals, examples, etc.

Any help would be appreciated.

Best Regards,
Deckard

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




--- End Message ---
--- Begin Message ---
Me... again, still boring you to death with meaningless OOP rantings.

First I would like to point out that there was a design mistake in what I
proposed in the last mail (following afterwards): the Saluter shouldn't be
an abstract class, it isn't correct to base your class hierarchy on the
ability to greet (or in the ability to do something generally speaking). If
it's done that way we'll have classes coexisting in the same branch of the
class tree, but possibly having completely different nature. Saluter should
be an interface:

 interface class Saluter {
   public function greet(Salutable $receiver);
 }

 class FormalSaluter implements Saluter {
   public function greet(Salutable $receiver) {
     echo "Hello " . $receiver->getSalutationName() . "\n";
   }
 }

Then, I'll try to translate what has been said in the spanish list.

It has been proposed that World should be a singleton, since there is only
one world... but this arguable, at metaphysic level perhaps...

Also an observer pattern could be used so anyone can hear the greetings. But
I think this should be done on the design of the greeting enviroment
abstraction (to provide other places than standard output where the greeting
can be said).

The saluters factory should use a factory method pattern or an abstract
factory pattern? I think an abstract factory is not appropiate in this case,
the creation process is not that complex to require this kind of design
pattern.

Also I proposed that decorators could be used to add styles to the greeting
for outputs that allow styling (e.g.:html). In this case maybe an abstract
factory would be appropiate, so that decorated saluters are created for the
appropiate type of output, combined with a builder pattern to create the
decorated saluters (this last part I thought it just now, I'll post it later
on the spanish list)

Well, I think that sums it all up.

2006/9/29, Martin Alterisio <[EMAIL PROTECTED]>:

What's up folks?

I just wanted to tell you about a thread that's going on in the spanish
php mailing list. A fellow software developer which had just started with
OOP was asking for "Hello World" examples using OOP. The examples of code he
had been doing was not that different from the usual Hello World example we
all know and love(?), so I thought he was missing the point of what was the
purpose of using OOP. This was my reply (I'll try to keep the translation as
accurate as possible):

I believe you have misunderstood what is the purpose of OOP, your objects
are not proper abstractions.

First and most important, you should define what is the problem to solve:
greet the world.
We build an abstraction of the problem and its main components: somebody
who greets and something to greet.
Here we're working with generalizations, since our main objective is to
build reusable objects. For that purpose is useful that our "saluter" could
be used to greet more than just the world.

Therefore we'll first define what kind of interaction we expect the
salutation receivers to have, in the following interface:

  interface Salutable {
    public function getSalutationName();
  }

In this interface we have all we need to properly greet any entity: the
name we should use when doing the salutation.

Then we create the object which represents the world:

  class World implements Salutable {
    public function getSalutationName() {
      return "World";
    }
  }

Now we're missing a saluter, but we're not sure which way of greeting
would be appropiate, so we prefer to create an abstract saluter and leave
the child implementation to decide the appropiate greeting:

  abstract class Saluter {
    abstract public function greet(Salutable $receiver);
  }

In our case we need a formal saluter as we should not disrespect the world
(saying "hey! wazzup world?" could be offensive), then:

  class FormalSaluter extends Saluter {
    public function greet(Salutable $receiver) {
      echo "Hello " . $receiver->getSalutationName() . "\n";
    }
  }

Finally we make our saluter greet the world:

  $saluter = new FormalSaluter();
  $world = new World();
  $saluter->greet($world);

----

Other things you should keep in mind:

* PHP's type hinting is preety limited, in this case we would like to
indicate that the name should be provided as a string but we can't. Maybe it
would be useful to use an object as a wrapper for native strings. EDIT: I
remembered while translating this that type hinting can only be used in
function parameters, therefore this point is useless.

* En this model it seems more appropiate that the saluter is an abstract
class, since salutation works one way, but, in the event salutations became
a two way trip, an interface would be more appropiate for the saluters.

* Here we're sending the salutation to the standard output, which is
acceptable in this case, but a more complex abstration would require us to
indicate where we should procede with the salutation, and we will have to
provide an abstraction for the possible salutation enviroments.

* A factory of saluters would be a nice feature.

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

That's it. If you find this interesting I'll try to keep up with the
translation of following posts.


--- End Message ---
--- Begin Message ---
Здравствуйте!
Мне сказали, что по этому адресу можно задать вопрос по использованию PHP.
Это правда?
С уважением, Николай Фурлетов.

--- End Message ---

Reply via email to