Search Results

Search found 3 results on 1 pages for 'ejaz'.

Page 1/1 | 1 

  • What is the disadvantage of using abstract class as a database connectivity in zend framework 2 instead of service locator

    - by arslaan ejaz
    If I use database by creating adapter with drivers, initialize it in some abstract class and extend that abstract class to required model. Then use simple query statement. Like this: namespace My-Model\Model\DB; abstract class MysqliDB { protected $adapter; public function __construct(){ $this->adapter = new \Zend\Db\Adapter\Adapter(array( 'driver' => 'Mysqli', 'database' => 'my-database', 'username' => 'root', 'password' => '' )); } } And use abstract class of database like this in my models: class States extends DB\MysqliDB{ public function __construct(){ parent::__construct(); } protected $states = array(); public function select_all_states(){ $data = $this->adapter->query('select * from states'); foreach ($data->execute() as $row){ $this->states[] = $row; } return $this->states; } } I am new to zend framework, before i have experience of working in YII and Codeigniter. I like the object oriented in zend so i want to use it like this. And don't want to use it through service locater something like this: public function getServiceConfig(){ return array( 'factories' => array( 'addserver-mysqli' => new Model\MyAdapterFactory('addserver-mysqli'), 'loginDB' => function ($sm){ $adapter = $sm->get('addserver-mysqli'); return new LoginDB($adapter); } ) ); } In module. Am i Ok with this approach?

    Read the article

  • UITableView not getting populated with sqlite database column

    - by Ingila Ejaz
    Here's the code of a method I used to populate UITableView with the contents of a column in sqlite database. However, this is giving no errors at run-time but still does not give any data in UITableView. If anyone could help, it'll be highly appreciated. - (void)viewDidLoad{ [super viewDidLoad]; self.title = @"Strings List"; UITableViewCell *cell; NSString *docsDir; NSArray *dirPaths; sqlite3_stmt *statement; // Get the documents directory dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; // Build the path to the database file databasePath = [[NSString alloc]initWithString: [docsDir stringByAppendingPathComponent:@"strings.sqlite"]]; NSFileManager *filemgr = [NSFileManager defaultManager]; if ([filemgr fileExistsAtPath: databasePath ] == NO) { const char *dbpath = [databasePath UTF8String]; if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK) { NSString * query = @"SELECT string FROM strings"; const char * stmt = [query UTF8String]; if (sqlite3_prepare_v2(contactDB, stmt, -1,&statement, NULL)==SQLITE_OK){ if (sqlite3_step(statement) == SQLITE_ROW) { NSString *string = [[NSString alloc]initWithUTF8String:(const char*)sqlite3_column_text(statement, 0)]; cell.textLabel.text = string; } } else NSLog(@"Failed"); sqlite3_finalize(statement); } sqlite3_close(contactDB); } }

    Read the article

  • Traverse multi dimensional array recusively without using foreach

    - by ejaz
    I have an array like this and the code using foreach loop. $arr = array( array ( array( 'CAR_TIR', 'Tires', 100 ), array( 'CAR_OIL', 'Oil', 10 ), array( 'CAR_SPK', 'Spark Plugs', 4 ) ), array ( array( 'VAN_TIR', 'Tires', 120 ), array( 'VAN_OIL', 'Oil', 12 ), array( 'VAN_SPK', 'Spark Plugs', 5 ) ), array ( array( 'TRK_TIR', 'Tires', 150 ), array( 'TRK_OIL', 'Oil', 15 ), array( 'TRK_SPK', 'Spark Plugs', 6 ) ) ); function recarray($array) { foreach($array as $key=>$value) { if(is_array($value)) { RecArray($value); } else { echo "key = $key value = $value"; } } } recarray($arr); I have to traverse the array using recursion and without using foreach. I would appreciate it if any one can help me

    Read the article

1