A PHP Error was encountered

Severity: Warning

Message: fopen(/tmp/ci_sessionc4929713701228c33325ca8d38784516): failed to open stream: Disk quota exceeded

Filename: drivers/Session_files_driver.php

Line Number: 156

Backtrace:

File: /home/s949hbuup34l/public_html/webphplearn.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Failed to read session data: user (path: /tmp)

Filename: Session/Session.php

Line Number: 140

Backtrace:

File: /home/s949hbuup34l/public_html/webphplearn.com/index.php
Line: 292
Function: require_once

How to Use Service Manager in Zend2
Apply for Zend Framework Certification Training

Zend Framework 2




 How to use mysql in Zend Framework 2.

Step 1  create a new model called employee, and in my module.php file and  add:

public function getServiceConfig()
{
  return array(
    'factories' => array(
        'Application\Model\Employee' => function($sm) {
        $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
        $table = new \Application\Model\Employee('employee', $dbAdapter);
         return $table;
},
),
);
}

In my Controller, I will connect the created model:

$select = $this->getCategoriesTable()->fetchAll();

Now, I will write a sql query in my model:

public function fetchAll()
{
$statement = $this->adapter->query('SELECT * FROM employee');
$results = $statement->execute();
return iterator_to_array($results); // will return an array
}
                                    

< Zend Framework 2 Interview Questions Part 1 Rajesh >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top