Skip to content

fix eloquent transaction not working #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ $resolver = new Illuminate\CodeIgniter\CodeIgniterConnectionResolver($ci);
Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
```

To enable events dispatcher support:

```php
// use our mock PDO class if PDO is not enabled on this server
if (!class_exists('PDO')) {
class_alias('Illuminate\CodeIgniter\FakePDO', 'PDO');
}

// pass all Laravel database queries through to CodeIgniter
$ci = get_instance();
$resolver = new Illuminate\CodeIgniter\CodeIgniterConnectionResolver($ci);

// create a new event dispatcher instance
$event_dispatcher = new Illuminate\Events\Dispatcher();
//create a new database manager instance
$database_manager = new Illuminate\Database\Capsule\Manager();
// attach the evebt dispatcher instance to the manager instance
$database_manager->setEventDispatcher($event_dispatcher);
// attach the event dispatcher to the eloquent
$database_manager->bootEloquent();

Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver);
```


## License

[MIT License](https://github.com/expressodev/laravel-codeigniter-db/blob/master/LICENSE)
9 changes: 8 additions & 1 deletion src/CodeIgniterConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public function __construct($ci)
$this->tablePrefix = $this->ci->db->dbprefix;
$this->useDefaultQueryGrammar();
$this->useDefaultPostProcessor();
try {
$this->pdo = new PDO("{$this->ci->db->dbdriver}:host={$this->ci->db->hostname};dbname={$this->ci->db->database};charset={$this->ci->db->char_set}", $this->ci->db->username, $this->ci->db->password);
} catch(Exception $e) {
if ($this->ci->db->dbdriver == "mysqli") {
$this->pdo = new PDO("mysql:host={$this->ci->db->hostname};dbname={$this->ci->db->database};charset={$this->ci->db->char_set}", $this->ci->db->username, $this->ci->db->password);
}
}
}

/**
Expand Down Expand Up @@ -74,7 +81,7 @@ protected function getDefaultPostProcessor()
*/
public function getPdo()
{
throw new \BadMethodCallException('PDO is not supported by CodeIgniter database driver');
return $this->pdo;
}

/**
Expand Down