php-windows Digest 22 Jun 2006 05:54:07 -0000 Issue 3001

Topics (messages 27050 through 27051):

Making sure that everything is OK
        27050 by: Simon Renshaw

Re: Transactions and PDO
        27051 by: Dale D. Attree

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 ---
Hi,

This is what I have currently running on my server:

Pear version:

PEAR Version: 1.4.9
PHP Version: 5.0.5
Zend Engine Version: 2.0.5
Running on: Windows NT CASTOR-SRVR1 5.2 build 3790

Pear list:

INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
=========================================
PACKAGE        VERSION STATE
Archive_Tar    1.3.1   stable
Console_Getopt 1.2     stable
DB             1.7.6   stable
Mail           1.1.10  stable
Net_SMTP       1.2.8   stable
Net_Socket     1.0.6   stable
PEAR           1.4.9   stable
PHPUnit        1.3.2   stable
XML_Parser     1.2.7   stable
XML_RPC        1.4.8   stable

Is there an easy way to test if my setup can send emails?

I've been trying to get my Mediawiki Wiki (it does require PEAR Mail) to
send email but I never receive them so I'm thinking that something is
wrong on the PHP side but I don't know what to check.

Thanks!
Simon

--- End Message ---
--- Begin Message ---
Why not create a Stored Procedure to handle the second table?

-----Original Message-----
From: Vandegrift, Ken [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 21, 2006 7:20 PM
To: [email protected]
Subject: [PHP-WIN] Transactions and PDO

Just wanted to throw this out there to see if anyone may be able to help
with a PDO transaction that does not appear to be working.  I want to
update an order record in the database and also insert giftcard numbers
associated with this same order into another table.  So I am trying to
do one update in the customer order table and possibly several inserts
into a giftcard record table.  I purposely use the same giftcard number
to trigger a primary key violation and attempt to rollback the
transaction if this occurs.  I know users of the system will likely
enter the same giftcard numer at some point (although I will have
validation schemes in place to prevent db errors)
 
Running Windows 2003 Server IIS6 and PHP 5.1.2
 
Code example:
 
/**
  * Updates order information in the database.
  * Called from Order::dbSaveOrder
  * @return boolean true on success
  * @access protected
  */
 protected function dbUpdateOrder() {
 
  // VARIABLES TO TRACK PROPER SQL FORMATTING
  $count = count($this->attributes);
  $i = 1;
 
  // BUILD ORDER TABLE UPDATE QUERY
  $sql = "UPDATE " . ORDER_TABLE . " SET ";
  foreach ($this->attributes as $attribute => $value) {
   $attribute = strtoupper($attribute);
   $sql      .= (is_string($value) || is_null($value)) ? "{$attribute} =
'{$value}'" : "{$attribute} = {$value}";
   if ($i < $count) {
    $i++;
    $sql .= ", ";
   }
  }
  $sql .= " WHERE " . ORDER_TABLE_ID . " = :orderid;";
 
  try {
   $this->db->beginTransaction();
   $stmt = $this->db->prepare($sql);
   $stmt->execute(array(':orderid' => $this->attributes['order_id']));
   $stmt = null;
   // SAVE GIFT CARD NUMBERS RECORDED FOR THIS ORDER
   if (!empty($this->gcnums)) {
    $sql = null;
    foreach ($this->gcnums as $itemid => $gcnumbers) {
      foreach ($gcnumbers as $gcnum) {
        $sql .= "INSERT INTO GIFTCARD_RECORD " .
                "(" .
                "ORDER_ID, " .
                "ITEM_ID, " .
                "GC_NUM " .
                ") " .
                "VALUES" .
                "(" .
                "{$this->__get('order_id')}, " .
                "{$itemid}, " .
                "'{$gcnum}'" .
                ");";
      } // End Inner FOREACH
       } // End Outer FOREACH
     $stmt = $this->db->prepare($sql);
     $stmt->execute();
   }
   $this->db->commit();
   return true;
  }catch (PDOException $e) {
   $this->db->rollBack();
   Log::write(LOG_DIR, 'order',
     "\r******** Order::dbUpdateOrder ********\r" .
     "[UPDATE SQL] => " . $sql . "\r" .
     "[DB ERROR] => " . $e->getMessage() . "\r" .
     "**************************************"
   );
   $this->error = 'The system has encountered an error and is unable to
update this order. ' .
     'Please contact the system administrator.';
   $stmt = null;
   return false;
  }
 }
 
Ken Vandegrift
 

--- End Message ---

Reply via email to