Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like a lot of other people you seem to be having difficulty with the quickstart, try the tutorial from <a href="http://akrabat.com/zend-framework-tutorial/" rel="nofollow noreferrer">Rob Allen</a> it helped me get started.<br /></p> <p>You have multiple choices on how to connect to your table, the confusion with Zend_Db often begins here.</p> <p>The easiest way when using one DB, in your <code>application.ini</code> file add these lines at a minmum:</p> <pre><code>resources.db.adapter = "pdo_Mysql" resources.db.params.username = "user_name" resources.db.params.password = "password" resources.db.params.dbname = "db_name" </code></pre> <p>Alternatively you can connect to a database almost anywhere in your code using the <a href="http://framework.zend.com/manual/en/zend.db.adapter.html" rel="nofollow noreferrer">Zend_Db_Adapter</a>:</p> <pre><code>//using a normal constructor $db = new Zend_Db_Adapter_Pdo_Mysql(array( 'host' =&gt; '127.0.0.1', 'username' =&gt; 'webuser', 'password' =&gt; 'xxxxxxxx', 'dbname' =&gt; 'test' )); //using factory $db = Zend_Db::factory('Pdo_Mysql', array( 'host' =&gt; '127.0.0.1', 'username' =&gt; 'webuser', 'password' =&gt; 'xxxxxxxx', 'dbname' =&gt; 'test' )); </code></pre> <p><a href="http://framework.zend.com/manual/en/zend.db.adapter.html" rel="nofollow noreferrer">List of supported Databases</a></p> <p>Using this in your application can be as simple as:</p> <pre><code>//fetchAll using Zend_Db_Adapter and plain SQL $sql = 'SELECT * FROM bugs WHERE bug_id = ?'; $result = $db-&gt;fetchAll($sql, 2); </code></pre> <p>you can list the tables in a database:</p> <pre><code>$tables = $db-&gt;listTables(); </code></pre> <p>or you can get a full table description (including column names), I included the comment block from the function in Zend_Db_Adapter_Abstract:</p> <pre><code> /** * Returns the column descriptions for a table. * * The return value is an associative array keyed by the column name, * as returned by the RDBMS. * * The value of each array element is an associative array * with the following keys: * * SCHEMA_NAME =&gt; string; name of database or schema * TABLE_NAME =&gt; string; * COLUMN_NAME =&gt; string; column name * COLUMN_POSITION =&gt; number; ordinal position of column in table * DATA_TYPE =&gt; string; SQL datatype name of column * DEFAULT =&gt; string; default expression of column, null if none * NULLABLE =&gt; boolean; true if column can have nulls * LENGTH =&gt; number; length of CHAR/VARCHAR * SCALE =&gt; number; scale of NUMERIC/DECIMAL * PRECISION =&gt; number; precision of NUMERIC/DECIMAL * UNSIGNED =&gt; boolean; unsigned property of an integer type * PRIMARY =&gt; boolean; true if column is part of the primary key * PRIMARY_POSITION =&gt; integer; position of column in primary key * * @param string $tableName * @param string $schemaName OPTIONAL * @return array */ $describTable = $db-&gt;describeTable('myTable'); </code></pre> <p>This info should get you started, however I find that a lot of the real power of Zend_Db resides in the <a href="http://framework.zend.com/manual/en/zend.db.table.html" rel="nofollow noreferrer">Zend_Db_Table</a>, <a href="http://framework.zend.com/manual/en/zend.db.table.row.html" rel="nofollow noreferrer">Zend_Db_Table_Row</a> and especially the <a href="http://framework.zend.com/manual/en/zend.db.select.html" rel="nofollow noreferrer">Zend_Db_Select</a> classes.</p> <p>I urge you to take some time and figure them out. </p> <p>As an example of what you might expect from Zend_Db_Table and Zend_Db_select (when not using more advanced mappers and domain objects, hopefully those will come later):</p> <pre><code>//When using DbTable models that extend Zend_Db_Table_Abstract the model already //knows the name of the table and has full access to the Db adapter, allowing your code to //be very brief and descriptive. class Application_Model_DbTable_Weekend extends Zend_Db_Table_Abstract { //name of table, required if classname is not the same as the table name protected $_name = 'weekend'; //primary key column of table, a good idea especially if primary key is not 'id' protected $_primary = 'weekendid'; public function getWeekend($weekendId) { //create select object $select = $this-&gt;select(); $select-&gt;where('weekendid = ?', $weekendId);//placeholder syntax $result = $this-&gt;fetchRow($select); if (!$result) { throw new Exception('Could not find weekend ID ' . $weekendId); } return $result;//returns a single row object } public function fetchAllWeekend() { $select = $this-&gt;select(); $result = $this-&gt;fetchAll($select); return $result; //returns array of row objects (rowset object) } } </code></pre> <p>Rob Allen's Zf tutorial will explain how DbTable models are setup and how they Work.</p> <p>hope this helps...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload