Re: [PHP] Help on objects

2006-10-06 Thread Richard Lynch
On Thu, October 5, 2006 2:55 pm, Satyam wrote:
   - Original Message -
   From: Martin Alterisio
   To: Satyam
   Cc: Deckard ; php-general@lists.php.net
   You're wrong, partially:

 I am sure you could have stated that in a more courteous way.

So, this Argentinian, Italian, and European walk into a mailing list...

:-) :-) :-)

Language constructs in English are probably not the best thing to
flame about on this list...

Back to the curly braces!
{?php echo $var1: $var2?}

Sorry. Couldn't resist.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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



Re: [PHP] Help on objects

2006-10-05 Thread John Wells

On 10/5/06, 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 commend you on trying to build an OOP class for database
abstraction.  Having already been there and done that, might I
introduce you quickly to one of the great advantages of OOP: reuse.

There are already many classes out there built to help accomplish
database interaction.  Yes it's an obvious place for OOP, but as your
first foray into the discipline, I think you're biting off more than
you can chew.

Alternatively, why not download and start using one of the many stable
and community-tested DB classes?  Believe me, I completely relate to
the need to build it myself, and I don't want to squash that (it's
the best way to learn).  I just don't think it's worth doing it for
database interaction.  It's just not beginner material, and it's
something you'll be using in all of your code from here on out, so
it's best to start with something stable...

My $.02.  Er, £.01.

HTH,
John W

p.s.  I'm sure you want suggestions of good DB classes to use.
Ironically, I use my own, so I don't have extensive experience in
others, but why not look at the Zend Framework (it's what I'm
switching to)?  No need to use the whole framework.  Or others on the
list will surely have their suggestions of classes to use...

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



Re: [PHP] Help on objects

2006-10-05 Thread Robert Cummings
On Thu, 2006-10-05 at 07:04 +0200, Satyam wrote:
 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.

Properties are very often nouns in addition to adjectives. For instance
a linked list class will undoubtedly have noun objects referring to the
current link, the next link, etc.

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

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



Re: [PHP] Help on objects

2006-10-05 Thread benifactor

- Original Message - 
From: Robert Cummings [EMAIL PROTECTED]
To: Satyam [EMAIL PROTECTED]
Cc: Deckard [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Thursday, October 05, 2006 2:16 AM
Subject: Re: [PHP] Help on objects


 On Thu, 2006-10-05 at 07:04 +0200, Satyam wrote:
  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.

 Properties are very often nouns in addition to adjectives. For instance
 a linked list class will undoubtedly have noun objects referring to the
 current link, the next link, etc.

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

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



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



Re: [PHP] Help on objects [with reply]

2006-10-05 Thread benifactor
i may be wrong, but your use of the class to me seems pointless... the reuse
aspect of your database connection could be done with a simple include...
maybe your need is different from what i suspect, being a beginner myself...
here is what i do, and maybe the list can tell me if it would be better or
worse for you...


in a seperate php file define your  database info...


?php
//begin database information

   $hostname = localhost;
   $db_user = nerd_mysite;
   $db_pass = pepsi_is_good;
   $database = nerd__pepsi;
   $l = @mysql_connect($hostname, $db_user, $db_pass);
   @mysql_select_db($database, $l);

//end database information
?

and in the all of the files you would need this connection you would just
include that file...and call the database with the variable $l.
example:

?

$nerdCheck = mysql_query(SELECT * FROM DrinkMorePepsi WHERE username =
'$_POST[username]', $l)

?

and this could easily be made into a function to allow for multiple
databases, users passwords, ect
if nothing else, at least tell me what you think about my way of doing this.
- Original Message - 
From: Robert Cummings [EMAIL PROTECTED]
To: Satyam [EMAIL PROTECTED]
Cc: Deckard [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Thursday, October 05, 2006 2:16 AM
Subject: Re: [PHP] Help on objects


 On Thu, 2006-10-05 at 07:04 +0200, Satyam wrote:
  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.

 Properties are very often nouns in addition to adjectives. For instance
 a linked list class will undoubtedly have noun objects referring to the
 current link, the next link, etc.

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

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



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



Re: [PHP] Help on objects [with reply]

2006-10-05 Thread Dave Goodchild

Re the last suggestion, ensure you keep those database details outside the
web root (ie in a file called connect.inc for example) or if have to keep it
there add a .htaccess file that prevents download of *.inc files.

Also, avoid use of the error suppression operator (@). You need to see your
errors.


Re: [PHP] Help on objects [with reply]

2006-10-05 Thread benifactor
yea, thanks for the input... but do you think my solution would be better
for original poster?
- Original Message - 
From: Dave Goodchild [EMAIL PROTECTED]
To: benifactor [EMAIL PROTECTED]
Cc: Robert Cummings [EMAIL PROTECTED]; Satyam
[EMAIL PROTECTED]; Deckard [EMAIL PROTECTED];
php-general@lists.php.net
Sent: Thursday, October 05, 2006 4:55 AM
Subject: Re: [PHP] Help on objects [with reply]


 Re the last suggestion, ensure you keep those database details outside the
 web root (ie in a file called connect.inc for example) or if have to keep
it
 there add a .htaccess file that prevents download of *.inc files.

 Also, avoid use of the error suppression operator (@). You need to see
your
 errors.


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



Re: [PHP] Help on objects [with reply]

2006-10-05 Thread Dave Goodchild

Undoubtedly. He could also use the PEAR DB abstraction layer.


Re: [PHP] Help on objects

2006-10-05 Thread Martin Alterisio

2006/10/4, Deckard [EMAIL PROTECTED]:


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



For database interaction, give PDO a chance: http://php.net/pdo
IMO it's cleaner and more efficient than adodb.

Then, I believe what you're trying to make is a query builder. I would break
down the differente parts of an sql query and create abstractions for each
part (some can be reused on different types of queries), then have builder
create the queries abstractions from the different parts.


Re: [PHP] Help on objects

2006-10-05 Thread Martin Alterisio

2006/10/5, Satyam [EMAIL PROTECTED]:


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



You're wrong, partially: an action can be an object and it's not necessarily
a bad design, take for example function objects or the program and
statements as objects in lisp-like languages. It's acceptable to make a
class that works as an abstract representation of an sql query. This kind of
classes are used very efficiently in object persistence libraries. What I
agree with you is that it's not right that this class works as the insert
action and not as a representation of the insert operation.


Re: [PHP] Help on objects

2006-10-05 Thread Satyam


- Original Message - 
From: Robert Cummings [EMAIL PROTECTED]

To: Satyam [EMAIL PROTECTED]
Cc: Deckard [EMAIL PROTECTED]; php-general@lists.php.net
Sent: Thursday, October 05, 2006 11:16 AM
Subject: Re: [PHP] Help on objects



On Thu, 2006-10-05 at 07:04 +0200, Satyam wrote:
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.


Properties are very often nouns in addition to adjectives. For instance
a linked list class will undoubtedly have noun objects referring to the
current link, the next link, etc.

Cheers,
Rob.
--


Indeed, they often are:  you as an object are defined by properties such as 
height, color of your hair and many other adjectives and you have many other 
objects which define you, fingers, legs, etc, which are also properties. 
Being more detailed, instead of the color of your hair being a property of 
you as a whole, you might have a property pointing to a hair object (a noun) 
which has a color property.


Other noun properties might not be so helpful in defining you, your friends 
might give a hint of who you are, your clients do not.  But, after all, 
neither does your hair, mine is deserting me and I'm still myself.  So, I 
would say that while adjectives define an object, nouns are relations in 
between objects and might not define neither.


Anyway, I didn't mean this analogy to be complete, nor I mean to teach OOP 
to English teachers, and though it can be talked much about, stretching it 
too far would certainly break it.  I don't mean to defend it very strongly.


Cheers

Satyam

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



Re: [PHP] Help on objects

2006-10-05 Thread Satyam

  - Original Message - 
  From: Martin Alterisio 
  To: Satyam 
  Cc: Deckard ; php-general@lists.php.net 
  Sent: Thursday, October 05, 2006 3:50 PM
  Subject: Re: [PHP] Help on objects


  2006/10/5, Satyam [EMAIL PROTECTED]:
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


  You're wrong, partially: 

I am sure you could have stated that in a more courteous way.

Re: [PHP] Help on objects

2006-10-05 Thread Martin Alterisio

2006/10/5, Satyam [EMAIL PROTECTED]:




- Original Message -
*From:* Martin Alterisio [EMAIL PROTECTED]
*To:* Satyam [EMAIL PROTECTED]
*Cc:* Deckard [EMAIL PROTECTED] ; php-general@lists.php.net
*Sent:* Thursday, October 05, 2006 3:50 PM
*Subject:* Re: [PHP] Help on objects

2006/10/5, Satyam [EMAIL PROTECTED]:

 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


You're wrong, partially:


I am sure you could have stated that in a more courteous way.



I apologize, english is not my first language and I usually can't express
myself correctly. As a fellow compatriot I hope you'll understand there
weren't ill intentions on what I said.


[PHP] Help on objects

2006-10-04 Thread Deckard
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



Re: [PHP] Help on objects

2006-10-04 Thread Penthexquadium
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.

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



Re: [PHP] Help on objects

2006-10-04 Thread Satyam
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: php-general@lists.php.net
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





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