Continuing the Zend_DB article series, we are stopping now at DML statements.

DML (Data Manipulation Language) statements are statements that change data values in database tables. There are 3 primary DML statements:

  • INSERT – Inserting new rows into database tables.
  • UPDATE – Updating existing rows in database tables .
  • DELETE – Deleting existing rows from database tables.




Note*:

$db = Zend_Db::factory('Pdo_Mysql', $dbConnect);



INSERT

INSERT INTO user(email, password, firstName, lastName, active)
	   VALUES ('$email', '$password', '$firstName', '$lastName', 1);

The above SQL INSERT statement is translated in Zend_Db as follow:

$data = array( 'email' => $email,
		    'password' => $password,
		    'firstName' => $firstName,
		    'lastName' => $lastName,
		    'active' => '1');
$db->insert('user', $data);



UPDATE

UPDATE user
   SET password = '$password',
       firstName = '$firstName',
       lastName = '$lastName',
       accountUpdate = (accountUpdate +1)
 WHERE id = '$id'

The above SQL UPDATE statemnet is translated in Zend_Db as follow:

$data = array('password' => $password,
              'firstName' => $firstName,
              'lastName' => $vlastname,
              'accountUpdate' => new Zend_Db_Expr('accountUpdate+1'));
$db->update('user', $data, 'id = '.$id);



DELETE

DELETE FROM user WHERE id = '$id'

The above SQL DELETE statemnet is translated in Zend_Db as follow:

$db->delete('user', 'id = '.$id);

Looking for PHP, Laminas or Mezzio Support?

As part of the Laminas Commercial Vendor Program, Apidemia offers expert technical support and services for:

  • Modernising Legacy Applications
  • Migration from any version of Zend Framework to Laminas
  • Migration from legacy Laminas API Tools (formerly Apigility) to Dotkernel API
  • Mezzio and Laminas Consulting and Technical Audit
  • 3 Comments

    1. igi ladera

      nice tutorial for beginner like me!!!! you ROCKZZZZZZ

    2. Daniel

      I use this site almost like php.net for Zend_db. Thanks!

    3. Bassam Gerges Hanna

      thanks alot, any idea how to do the replace row in zend ? \m/

    Leave a Reply to Daniel Cancel Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>