Re: Help on objects

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 05 Oct 2006 02:47:59 +0100, Deckard <ml@xxxxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux