After a long struggle and research, I have finally been able to query a database in mysql table using zend framework 2.
I am using the Autoloader. Here is the code:
require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
use Zend\Db\Adapter\Adapter;
$params = array(
'driver'=> 'Pdo_Mysql',
'hostname' => 'localhost',
'username' => '*****',
'password' => '*****',
'dbname' => '*****'
);
try{
$adapter = new Adapter($params);
}
catch (Exception $e){
echo $e->getMessage();
}
$sql = 'select * from user';
$rs = $adapter->createStatement($sql)->execute(array(100,100));
print_r(iterator_to_array($rs));
echo $rs->count();
I want to know what is the correct way and best practice to query a mysql table. It used to be much easier in ZF1 but now I understand that ZF2 is much more object oriented.
I want to optimise performance and good coding. Can you tell me if what I did is good and what is the best way to query mysql database when using ZF2 as there will be a lot of querying to do.