Git Product home page Git Product logo

laravel-odbc's Introduction

ODBC integration for Laravel Framework

This integration allows the use of odbc_* php function with Laravel framework instead of PDO.
It emulates PDO class used by Laravel.

# How to install

composer require abram/laravel-odbc To add source in your project

# Usage Instructions

It's very simple to configure:

1) Add database to database.php file

'odbc-connection-name' => [
    'driver' => 'odbc',
    'dsn' => 'OdbcConnectionName',
    'database' => 'DatabaseName',
    'host' => '127.0.0.1',
    'username' => 'username',
    'password' => 'password'
]

2) Add service provider in app.php file

'providers' => [
  ...
  Abram\Odbc\ODBCServiceProvider::class
]

# Eloquen ORM

You can use Laravel, Eloquent ORM and other Illuminate's components as usual.

# Facade
$books = DB::connection('odbc-connection-name')->table('books')->where('Author', 'Abram Andrea')->get();

# ORM
$books = Book::where('Author', 'Abram Andrea')->get();

# Custom getLastInsertId() function

If you want to provide a custom getLastInsertId() function, you can extends ODBCProcessor class and override function.

class CustomProcessor extends ODBCProcessor
{
    /**
     * @param Builder $query
     * @param null $sequence
     * @return mixed
     */
    public function getLastInsertId(Builder $query, $sequence = null)
    {
        return $query->getConnection()->table($query->from)->latest('id')->first()->getAttribute($sequence);
    }
}

# Custom Processor / QueryGrammar / SchemaGrammar

To use another class instead default one you can update your connection in:

'odbc-connection-name' => [
    'driver' => 'odbc',
    'dsn' => 'OdbcConnectionName',
    'database' => 'DatabaseName',
    'host' => '127.0.0.1',
    'username' => 'username',
    'password' => 'password',
    'options' => [
        'processor' => Illuminate\Database\Query\Processors\Processor::class,   //default
        'grammar' => [
            'query' => Illuminate\Database\Query\Grammars\Grammar::class,       //default
            'schema' => Illuminate\Database\Schema\Grammars\Grammar::class      //default
        ]
    ]
]

laravel-odbc's People

Contributors

andreossido avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

laravel-odbc's Issues

No error: PDO constructor was not called

Hi,

The error :

⚠: ThrowingCasterException {#262 ▼ #message: "Unexpected ErrorException thrown from a caster: PDO::getAttribute(): SQLSTATE[00000]: No error: PDO constructor was not called" trace: {▼ C:\laragon\www\ppe3\vendor\symfony\var-dumper\Caster\PdoCaster.php:63 {▶} C:\laragon\www\ppe3\vendor\symfony\var-dumper\Cloner\AbstractCloner.php:231 {▶} Symfony\Component\VarDumper\Cloner\AbstractCloner->Symfony\Component\VarDumper\Cloner\{closure}() {} C:\laragon\www\ppe3\vendor\symfony\var-dumper\Caster\PdoCaster.php:63 {▶} } } #connection: odbc link resource @233

Migrations not working

The ODBC package is working perfectly but migrations are not working. I am using HANA SQL. Please resolve this issue.

Issues with instalation

The command

composer require abram/laravel-odbc

gives:

Could not find a version of package abram/laravel-odbc matching your minimum-stability (stable). Require it with an explicit version constraint allowing its desired stability.

With PHP 8.3 And Laravel 10 (with Orchid)

Add Support for Laravel 6

Can you please add support for Laravel 6?
"support ~5.1" & "illuminate/database ~5.1" is required, but it should be e.g. ~6.0

PSR-4 autoloader instead of class map

In the composer.json file is call map used for autoloading:

	"autoload": {
		"classmap": [
			"src"
		]
	},

I would recommend to use PSR-4 for follwing reasons:

  • Lavarel standard is PSR-4
  • Classes in subfolders like src/grammars are loaded automatically with namespace Abram\ODBC\Grammars
  • This opens the possibility to add grammars for different databases eg. SAP SQL Anywhere via Pull request
   "autoload": {
        "psr-4": {
            "Abram\\ODBC\\": "src/"
        }
    },

With current solution I have to put the grammar classes in 'App' Folder somewhere in order that autoloader can find the grammar classes.

SQL compilation error when persisting data from ODBC connection to Laravel application

Hi there,

I've been using this package to create a connection to my data cloud Snowflake, and it works like a charm!
The problem is when I try to persist this data coming from snowflake to my Laravel model.
Here's the error:

odbc_prepare(): SQL error: SQL compilation error: Table '"blackboard_ultimo_login"' does not exist or not authorized., SQL state 42S02 in SQLPrepare (SQL: insert into "blackboard_ultimo_login" ("user_id", "name", "email", "funcao", "ultimo_login", "updated_at", "created_at") values (5855, Valdevane, [email protected], S, 2017-06-12 22:30:22, 2021-08-13 16:13:11, 2021-08-13 16:13:11))

Already try to use double quotes and call db name + schema + table name but did not work.

SYNTAX_ERROR: line 1:1: Incorrect number of parameters: expected 1 but found 0

Illuminate\Database\QueryException: PHP Warning:  odbc_prepare(): SQL error: [Simba][Athena] (1040) An error has been thrown from the AWS Athena client. Athena Error No: 102, HTTP Response Code: 1, Error Message: SYNTAX_ERROR: line 1:1: Incorrect number of parameters: expected 1 but found 0 [Execution ID: <redacted>], SQL state 37000 in SQLPrepare in /home/forge/app/vendor/abram/laravel-odbc/src/ODBCPdoStatement.php on line 28 (SQL: select * from "qa_lines_csv" where "id" > 100 limit 1) in /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
Stack trace:
#0 /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(624): Illuminate\Database\Connection->runQueryCallback('select * from "...', Array, Object(Closure))
#1 /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(333): Illuminate\Database\Connection->run('select * from "...', Array, Object(Closure))
#2 /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2095): Illuminate\Database\Connection->select('select * from "...', Array, true)
#3 /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2083): Illuminate\Database\Query\Builder->runSelect()
#4 /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2569): Illuminate\Database\Query\Builder->Illuminate\Database\Query\{closure}()
#5 /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2084): Illuminate\Database\Query\Builder->onceWithColumns(Array, Object(Closure))
#6 /home/forge/app/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php(77): Illuminate\Database\Query\Builder->get(Array)
#7 /home/forge/app/vendor/psy/psysh/src/ExecutionLoopClosure.php(55) : eval()'d code(2): Illuminate\Database\Query\Builder->first()
#8 /home/forge/app/vendor/psy/psysh/src/ExecutionLoopClosure.php(55): eval()
#9 /home/forge/app/vendor/psy/psysh/src/ExecutionClosure.php(101): Psy\{closure}()
#10 /home/forge/app/vendor/psy/psysh/src/ExecutionLoop.php(33): Psy\ExecutionClosure->execute()
#11 /home/forge/app/vendor/psy/psysh/src/Shell.php(351): Psy\ExecutionLoop->run(Object(Psy\Shell))
#12 /home/forge/app/vendor/symfony/console/Application.php(145): Psy\Shell->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Psy\Output\ShellOutput))
#13 /home/forge/app/vendor/psy/psysh/src/Shell.php(316): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Psy\Output\ShellOutput))
#14 /home/forge/app/vendor/laravel/tinker/src/Console/TinkerCommand.php(62): Psy\Shell->run()
#15 [internal function]: Laravel\Tinker\Console\TinkerCommand->handle()
#16 /home/forge/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#17 /home/forge/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#18 /home/forge/app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#19 /home/forge/app/vendor/laravel/framework/src/Illuminate/Container/Container.php(572): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#20 /home/forge/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#21 /home/forge/app/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#22 /home/forge/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#23 /home/forge/app/vendor/symfony/console/Application.php(901): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /home/forge/app/vendor/symfony/console/Application.php(262): Symfony\Component\Console\Application->doRunCommand(Object(Laravel\Tinker\Console\TinkerCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 /home/forge/app/vendor/symfony/console/Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 /home/forge/app/vendor/laravel/framework/src/Illuminate/Console/Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 /home/forge/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#28 /home/forge/app/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

when attempting to run:

DB::connection('test_athena')->table('qa_lines_csv')->where('id', '>', 100)->first()

When looking at the source code, my best guess is that this library only supports :named parameters, but not ? parameters, or that it's not yet supporting parameters in general.

Update for Laravel 6/7?

Hi there,

I recently started using Laravel and found out about your ODBC driver, while the documentation and all seems fine. I cannot install it on my Laravel 7 project. The dependencies say to not install Laravel framework 7+.

Can you provide some solution for this?

Thank you in advance.

Out of memory issue

Symfony\Component\Debug\Exception\FatalErrorException
Out of memory (allocated 2097152) (tried to allocate 140204912410631 bytes)

I've configured a Firebird Database: It works on terminal and its the same DSN.

I tried to increase memory from php.ini, but it still needing more.

How can I solve it?

Cursor type changed, SQL state 01S02 in SQLExecute

Hi. first thanks for this tool. I have this error and not if I am missing something in the configuration:

not work:
1.-$db->select("exec dbo.s_cob_login 'username','password' ");
error:
[ODBC Driver 17 for SQL Server]Cursor type changed, SQL state 01S02 in SQLExecute.

this if it works:
(esto si funciona )
1.- DB::connection('odbc')->table('tbl_usuario')->where('username', 'username')->get()
2.- $db->select(" select * from tbl_users where ...")

	'odbc' => [
		'driver' => 'odbc',
		'dsn' => 'testodbc1',
		'database' => env('DB_SCJ_DATABASE'),
		'host' => env('DB_SCJ_HOST'),
		'username' => 'xxxxx',
		'password' => 'xxxx'

gracias.

Can't make it to work

i am using the following connection

'odbc-connection-name' => [ 'driver' => 'odbc', 'dsn' => 'Driver={SQL Server};Server=myserver;Database=db;', 'database' => env('DB_DATABASESQL', 'forge'), 'host' => env('DB_HOSTSQL', 'localhost'), 'username' => env('DB_USERNAMESQL', 'forge'), 'password' => env('DB_PASSWORDSQL', ''), ],

i get PHP Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/app/current/vendor/abram/laravel-odbc/src/ODBCPdo.php on line 20

am i doing something incorrect or is it a bug?

No Support SqlServerGrammar

Not support SqlServerGrammar, just grammar default.

'options' => [
'processor' => Illuminate\Database\Query\Processors\SqlServerProcessor::class,
'grammar' => [
'query' => Illuminate\Database\Query\Grammars\SqlServerGrammar::class,
'schema' => Illuminate\Database\Schema\Grammars\SqlServerGrammar::class
]

help: Call to undefined function Abram\Odbc\odbc_connect()

PHP Error:  Call to undefined function Abram\Odbc\odbc_connect() in /home/carlomigueldy/projects/ajt-dashboard/api/vendor/abram/laravel-odbc/src/ODBCPdo.php on line 20

I just installed the package, I am using WSL 2, Laravel version 8. How do I install ODBC driver for Ubuntu WSL2?

What is your recommendation?

Not working with php8.*

I have installed the libraby as mentioned in the readme file, but not sure why I'm getting the non compatibility fatal error for pdo functions.

The error is Declaration of Abram\Odbc\ODBCPdoStatement::fetchAll($how = null, $class_name = null, $ctor_args = null) must be compatible with PDOStatement::fetchAll(int $mode = PDO::FETCH_BOTH, mixed ...$args)

Can you please help me to fix this?

Error, you must override this method! lastInsertId($name = null)

i try use this package in laravel 6.x but dosn work, and i use in laravel 5.8 but when i work with a user model and i try to insert the application give me a next error.

Exception
Error, you must override this method!

public function lastInsertId($name = null)
{
throw new Exception("Error, you must override this method!");
}

what is the solution for this, i work in windows with sybase database.

PDO constructor was not called

I'm getting the following error when Telescope is enabled. Any advice?
PDO::quote(): SQLSTATE[00000]: No error: PDO constructor was not called

Models

Hi, I been trying to use this with sybase and it work, i don't think my next question is a issue but can i use normal models for tables with this type o connection? hope anyone can respond soon

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.