Comments (8)
Due to several times this question were raised to me, I've decided to explore the possibility of stand alone usage and so here we go: ^_^
- add
"yajra/laravel-oci8": "1.*"
on your composer then runcomposer install
- create
database.php
and add the code below
require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
use yajra\Oci8\Connectors\OracleConnector;
use yajra\Oci8\Oci8Connection;
$capsule = new Capsule;
$manager = $capsule->getDatabaseManager();
$manager->extend('oracle', function($config)
{
$connector = new OracleConnector();
$connection = $connector->connect($config);
$db = new Oci8Connection($connection, $config["database"], $config["prefix"]);
// set oracle date format to match PHP's date
$db->setDateFormat('YYYY-MM-DD HH24:MI:SS');
return $db;
});
$capsule->addConnection(array(
'driver' => 'oracle',
'host' => 'oracle.host',
'database' => 'xe',
'username' => 'user',
'password' => 'password',
'prefix' => '',
'port' => 1521
));
$capsule->bootEloquent();
- Now we can start working with database tables just like we would if we were using Laravel!
include 'database.php';
// Create the User model
class User extends Illuminate\Database\Eloquent\Model {
public $timestamps = false;
}
// Grab a user with an id of 1
$user = User::find(1);
echo $user->toJson(); die();
Thanks to http://www.edzynda.com/use-laravels-eloquent-orm-outside-of-laravel/ for the idea on how to implement this.
Please provide a feedback if this works and will add the snippet on read me. Thanks!
from laravel-oci8.
Hey, thanks for the answer!
I'm getting null $instance inside Manager functions: "Call to a member function connection() on null @ illuminate/database/Illuminate/Database/Capsule/Manager.php:85".
Here's test code I use:
// Check that we have working DB
$conn = oci_pconnect('zq', 'zq', '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))');
oci_close($conn);
// Try to do the magic
use Illuminate\Database\Capsule\Manager as Capsule;
use yajra\Oci8\Connectors\OracleConnector;
use yajra\Oci8\Oci8Connection;
$DB = new Capsule;
$DB->getDatabaseManager()->extend('oracle', function ($config) {
$connection = (new OracleConnector)->connect($config);
$db = new Oci8Connection($connection, $config["database"], $config["prefix"]);
$db->setDateFormat('YYYY-MM-DD HH24:MI:SS');
return $db;
});
$DB->addConnection(array(
'driver' => 'oracle',
'host' => 'localhost',
'database' => 'orcl',
'service_name' => 'orcl',
'username' => 'zq',
'password' => 'zq',
'prefix' => '',
'port' => 1521
));
$DB->bootEloquent();
$row = $DB->table('dual')->first();
print_r($row);
It's worth noting that IDEA for some reason complains that there's no "extend" method as well.
from laravel-oci8.
The issue is on $DB->table()
try using $row = $DB->getConnection()->table('dual')->first();
instead.
However, the weird part is that the default connection is not loaded. Will check on that part or maybe it's just the way it works when accessing DB directly? Not really sure atm coz i haven't tried using the package outside Laravel.
from laravel-oci8.
reviewing Laravel's API and confirmed that you indeed need to get the connection. Your $DB
variable is just a Capsule and not an actual connection.
from laravel-oci8.
Thanks a lot! I was able to get it to connect and run test query.
From the initial benchmarks it looks though that for some reason it is horrendously slow (or maybe it's me not used to big fancy libraries?). Like 50 reqs/sec for a simple select, as compared to 500+ reqs/sec for oci_parse/execute/fetch. I've hard-coded pconnect just to be sure.
from laravel-oci8.
I would agree that it was slow due to "big fancy libraries" and the package also performs additional queries even for simple select which are required for this to work on Laravel.
Anyways, glad I was able help and to know that this package works as stand alone. ^_^
from laravel-oci8.
// Set the event dispatcher used by Eloquent models... (optional)
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
$capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();
from laravel-oci8.
thanks!
from laravel-oci8.
Related Issues (20)
- Materialized view HOT 2
- Case Sensitivity Issue with Alias Names HOT 2
- Improve pagination for newer oracle
- "sessionVars" config are ignored HOT 1
- Binding driver options are ignored when calling addBindingsToStatement method HOT 4
- OCI_DEFAULT Undefined HOT 2
- lock/lockForUpdate locks up all rows even combined with limit (Job Queue becomes unusable on large table) HOT 3
- Updating model with multiple blob columns fails
- DRCP Connection Pooling HOT 4
- Undefined type 'Yajra\Oci8\Oci8ServiceProvider'. HOT 5
- Method Yajra\Oci8\Schema\Grammars\OracleGrammar::compileColumns does not exist. HOT 2
- v10.4.3 introduced SQL error in SELECT FOR UPDATE HOT 4
- OracleProcessor.php function processColumns donot return key "auto_increment" HOT 2
- OCI_SUCCESS_WITH_INFO: ORA-28002: the password will expire within 13 days HOT 2
- Laravel 11 support is on the road? HOT 5
- [11.x] This database engine does not support inserting while ignoring errors.
- [11.x] Error Code : 942 Error Message : ORA-00942, Sessions table HOT 1
- Support PHP 8.3 With Laravel 10.x HOT 1
- Error LogicException This database driver does not support modifying columns HOT 1
- `Schema::dropIfExists()` not working in 11.2.2+ HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-oci8.