What am I doing wrong?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

What am I doing wrong?

Troy Marker
I am working on saving some user information the a database and can not  
figure how to get it working. I have use the examples from the manual, and  
nothing seems to work. Here is the code I am using:

     public static function adduser()
     {
         $params = array ('host'     => '127.0.0.1',
                          'username' => 'root',
                          'password' => 'asdf9685',
                          'dbname'   => 'tecg');
         $db = Zend_Db::factory('pdoMysql', $params);
         //Zend_Db_Table::setDefaultAdapter($db);
         //$table = new TecgUsers();
         //$table = new Teebl_Model_User_UserTable();
         $table = 'tecg_users';
         echo "Username: ".self::$fields['UserName']."<br>";
         echo "Password: ".self::$fields['Password']."<br>";
         echo "Email: ".self::$fields['Email']."<br>";
         $data = array('login' => self::$fields['UserName'],
                       'pw'    => md5(self::$fields['password']),
                       'email' => self::$fields['Email']);
        echo "After data assignment.<br>";
        $rows_affected = $db->insert($table, $data);
        echo "Rows: ".$rows_afected."<br>";
     }


The commented out lines are other attempts that failed. The echo  
statements are there so I can tell where the code stopped working. I get  
all the echo's except the last one, which is telling me that the script  
stops working the the $db->insert command.

Any help would be greatly apreciated.
Troy
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Reply | Threaded
Open this post in threaded view
|

Re: What am I doing wrong?

Art Hundiak
Hi Troy,

This really should work.
$table = 'tecg_users';
$data = array('login' => 'loginx',
              'pw'    => 'passwordx',
              'email' => 'emailx',
);
$db->insert($table, $data);

Are you getting errors or anything?  Make sure your data array actually
has valid data and that the names match the column names.  Not sure if you
need to do anything special for the primary key assuming you have one.  Be
nice if the manual included the schema for round_table.

I like the table/row classes:

class AccountTable extends Zend_Db_Table
{
        protected $_name    = 'account';     // Table Name
        protected $_primary = 'account_id';  // Promary key name
}
$accountTable = new AccountTable;
$account = $accountTable->fetchNew();  // Or fetchRow for existing records
$account->name = 'whatever';
$account->save();

>
> I am working on saving some user information the a database and can not
> figure how to get it working. I have use the examples from the manual, and
> nothing seems to work. Here is the code I am using:
>
>      public static function adduser()
>      {
>          $params = array ('host'     => '127.0.0.1',
>                           'username' => 'root',
>                           'password' => 'asdf9685',
>                           'dbname'   => 'tecg');
>          $db = Zend_Db::factory('pdoMysql', $params);
>          //Zend_Db_Table::setDefaultAdapter($db);
>          //$table = new TecgUsers();
>          //$table = new Teebl_Model_User_UserTable();
>          $table = 'tecg_users';
>          echo "Username: ".self::$fields['UserName']."<br>";
>          echo "Password: ".self::$fields['Password']."<br>";
>          echo "Email: ".self::$fields['Email']."<br>";
>          $data = array('login' => self::$fields['UserName'],
>                        'pw'    => md5(self::$fields['password']),
>                        'email' => self::$fields['Email']);
>         echo "After data assignment.<br>";
>         $rows_affected = $db->insert($table, $data);
>         echo "Rows: ".$rows_afected."<br>";
>      }
>
>
> The commented out lines are other attempts that failed. The echo
> statements are there so I can tell where the code stopped working. I get
> all the echo's except the last one, which is telling me that the script
> stops working the the $db->insert command.
>
> Any help would be greatly apreciated.
> Troy
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>
>


Reply | Threaded
Open this post in threaded view
|

Re: What am I doing wrong?

Troy Marker
Art,
Thanks for responding. I found out what was wrong. I am using my home pc  
to test my application, and I did not have the PDO extensions installed. I  
guess that is what happens when you first start trying to run a server.

Thanks again for the help,
Troy

On Sun, 04 Jun 2006 09:06:33 -0500, Art Hundiak <[hidden email]> wrote:

> Hi Troy,
>
> This really should work.
> $table = 'tecg_users';
> $data = array('login' => 'loginx',
>               'pw'    => 'passwordx',
>               'email' => 'emailx',
> );
> $db->insert($table, $data);
>
> Are you getting errors or anything?  Make sure your data array actually
> has valid data and that the names match the column names.  Not sure if  
> you
> need to do anything special for the primary key assuming you have one.  
> Be
> nice if the manual included the schema for round_table.
>
> I like the table/row classes:
>
> class AccountTable extends Zend_Db_Table
> {
> protected $_name    = 'account';     // Table Name
> protected $_primary = 'account_id';  // Promary key name
> }
> $accountTable = new AccountTable;
> $account = $accountTable->fetchNew();  // Or fetchRow for existing  
> records
> $account->name = 'whatever';
> $account->save();
>
>>
>> I am working on saving some user information the a database and can not
>> figure how to get it working. I have use the examples from the manual,  
>> and
>> nothing seems to work. Here is the code I am using:
>>
>>      public static function adduser()
>>      {
>>          $params = array ('host'     => '127.0.0.1',
>>                           'username' => 'root',
>>                           'password' => 'asdf9685',
>>                           'dbname'   => 'tecg');
>>          $db = Zend_Db::factory('pdoMysql', $params);
>>          //Zend_Db_Table::setDefaultAdapter($db);
>>          //$table = new TecgUsers();
>>          //$table = new Teebl_Model_User_UserTable();
>>          $table = 'tecg_users';
>>          echo "Username: ".self::$fields['UserName']."<br>";
>>          echo "Password: ".self::$fields['Password']."<br>";
>>          echo "Email: ".self::$fields['Email']."<br>";
>>          $data = array('login' => self::$fields['UserName'],
>>                        'pw'    => md5(self::$fields['password']),
>>                        'email' => self::$fields['Email']);
>>         echo "After data assignment.<br>";
>>         $rows_affected = $db->insert($table, $data);
>>         echo "Rows: ".$rows_afected."<br>";
>>      }
>>
>>
>> The commented out lines are other attempts that failed. The echo
>> statements are there so I can tell where the code stopped working. I get
>> all the echo's except the last one, which is telling me that the script
>> stops working the the $db->insert command.
>>
>> Any help would be greatly apreciated.
>> Troy
>> --
>> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>>
>>
>
>
>
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/