Trying to connect Laravel with DB2 database with odbc driver - php

I'm on a Laravel 5.2 based project, I've to connect it with a DB2 database hosted on an IBM i-series server, I've tried some plugins but this one seems to correspond to my needs :
https://github.com/bencarter78/odbc
I followed the installation steps, filled the database.php file, created a model and a controller but the page keeps returning :
PDOException in Connector.php line 55: invalid data source name
There is my controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\DB;
use App\didactp1;
class didactitiel extends Controller
{
public function recupererDidactitiels()
{
$didactitiels = didactp1::all();
return view('didactitiel')->with('didactitiels', $didactitiels);
}
}
My model :
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class didactp1 extends Model
{
protected $connection = 'odbc';
}
But I think the problem comes from the database.php file configuration but I can't find what's wrong :
'odbc' => [
'driver' => 'odbc',
'dsn' => 'AS400',
'host' => 'TheIpOfTheHostingServer',
'database' => 'myDatabaseName',
'username' => 'com11',
'password' => 'pcs400',
],
I tried to connect to the database manually with unixODBC :
error log
odbc.ini
I also tried the $sudo iptables -L command
iptables
Hope that's clear enought, every kind of help is welcome

Related

SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time,

I try to connect 2 database in my Laravel 5.6 project, but i got error like this
SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (SQL: select * from mt_merchant)
I tried following code:
.env
1st db connection (this is in my local server)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=thedaldb
DB_USERNAME=root
DB_PASSWORD=
2nd db connection (this is in live server IP 18.188.209.59)
DB_CONNECTION_SECOND=mysql
DB_HOST_SECOND= 18.188.209.59
DB_PORT_SECOND=3306
DB_DATABASE_SECOND=delivery_test_copied
DB_USERNAME_SECOND=testuser
DB_PASSWORD_SECOND=testuser#123
app/config/database.php
'connections' => [
'onlineorder' => [
'driver' => env('DB_CONNECTION_SECOND'),
'host' => env('DB_HOST_SECOND'),
'port' => env('DB_PORT_SECOND'),
'database' => env('DB_DATABASE_SECOND'),
'username' => env('DB_USERNAME_SECOND'),
'password' => env('DB_PASSWORD_SECOND'),
],
]
app/Models/OnlineOrder/OnlineOrder.php
<?php
namespace App\Models\OnlineOrder;
use Illuminate\Database\Eloquent\Model;
class OnlineOrder extends Model
{
protected $connection = 'onlineorder';
}
app/Http/Controllers/Onlineorder/AppOnlineOrderController.php
<?php
namespace App\Http\Controllers\Onlineorder;
use Symfony\Component\HttpKernel\Exception\HttpException;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use App\Models\OnlineOrder\OnlineOrder;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Validator;
use Config;
use File;
use DB;
class AppOnlineOrderController extends Controller
{
public function test($merchant_id)
{
$db_ext = DB::connection('onlineorder');
$merchant = $db_ext->table('mt_merchant')->get(); //mt_merchant is table name
print_r($db_ext);exit;
}
}
Simply i want to connect live server database in my local sever project
IP address always changes during time ... instead of using directed IP use main domain
like :
DB_HOST_SECOND=mydomain.com.sd
i think this will do
At the "Connectivty and Security" of your RDS instance page check if the configuration have "Public Accesibility" on "Yes" option. Maybe you don't have a public IP associated to your instance.
https://aws.amazon.com/premiumsupport/knowledge-center/rds-connectivity-instance-subnet-vpc/

Laravel passport install on dynamic database

I am creating database for each client registration in my laravel application. I have installed passport for authorization. I have successfully created database and ran migration for passport also. The passport:install command is not working for newly created database. Is there any way to run command passport:install for my new database.
$this->info(sprintf("Dropping database if exists : %s", $dbName));
DBHelper::drop($dbName);
$this->info("Setting up database for client");
//Create migration table
Artisan::call("migrate:install", array(
"--database" => DBHelper::connect($dbName)
));
//Run migration
Artisan::call('migrate',
array('--path' => 'database/migrations/client',
'--database' => DBHelper::connect($dbName))); //DBHelper::connect($dbName) : Create new database config and then DB::reconnect()
//Install passport migration
Artisan::call('migrate', ['--path' => 'vendor/laravel/passport/database/migrations']);
//Install passport
Artisan::call('passport:install');
//Populate database
Artisan::call('db:seed',
array('--database' => DBHelper::connect($dbName)));
After creating database use bellow commands for creating migrations and install passport.
Artisan::call('migrate:refresh', ['--seed' => true]);
Artisan::call('migrate',['--path' => 'vendor/laravel/passport/database/migrations','--force' => true]);
shell_exec('php ../artisan passport:install');
Usually you would use the following code in your controller to excute an Artisan call:
Artisan::call('passport:install');
However, this doesn't work on passport:install and you will get the error:
There are no commands defined in the "passport" namespace
To fix this you must add the following code to boot method at AppServiceProvider.php :
<?php
namespace App\Providers;
use Laravel\Passport\Console\ClientCommand;
use Laravel\Passport\Console\InstallCommand;
use Laravel\Passport\Console\KeysCommand;
use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
Schema::defaultStringLength(191);
Passport::routes();
/*ADD THIS LINES*/
$this->commands([
InstallCommand::class,
ClientCommand::class,
KeysCommand::class,
]);
}

Changing Path for User Class in Laravel

I moved the User.php in my laravel installation to a different folder and adjusted the namespace accordingly. Still, when I login into the page, laravel is not able to find the class and throws an error.
I ran composer clear-cash and composer dump-autoload but still it is not working as Laravel still searches for App/User.php instead of App/Classes/User/User.php
The User.php looks like this:
namespace App\Classes\User;
use App\Events\EventGenerator;
use App\Events\User\UserRegistered;
use App\Permission;
use App\Role;
use Laratrust\Traits\LaratrustUserTrait;
use \Illuminate\Contracts\Auth\Authenticatable as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Console\Command;
class User extends Model implements Authenticatable {
use EventGenerator;
(...)
You need to change the class the path in auth.php
In your auth.php
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Classes\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
Idea is to change the path of 'model' => App\Classes\User::class, to your class.
Hope this helps
There is a reference to the user model in auth config, you'll probably need to adjust the namespace there.
File: config/auth.php
Setting: providers -> users -> model

CakePhp 3 Plugin Authentication adapter was not found

I'm kinda a newbie in Cakephp (3.5) and I'm currently trying to make my first plugin (called Example) which contains several sub-directories. One of them is the UserManager directory which contains a Users MVC standard suit with authentication.
Since I want to add social logins and other stuffs, I created my own auth component as explained in the docs :
plugins/Example/UserManager/src/Controller/AppController.php
<?php
namespace Example\UserManager\Controller;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Example/UserManager.Example' => [
'fields' => ['username' => 'email', 'password' => 'pass'],
'userModel' => 'Users',
],
],
]);
}
}
plugins/Example/UserManager/src/Auth/ExampleAuthenticate.php
<?php
namespace App\Auth;
use Cake\Auth\BaseAuthenticate;
use Cake\Http\ServerRequest;
use Cake\Http\Response;
class ExampleAuthenticate extends BaseAuthenticate
{
// The same as Form authentication, since I'm testing
}
The problem is that I can't make the authentication component find the ExampleAuthenticate class. I already tried by setting the authenticate config param like
Example
ExampleAuthenticate
UserManager.Example
Example/UserManager.Example
Example\UserManager.Example
Example/UserManager.ExampleAuthenticate
Example\UserManager.ExampleAuthenticate
but I always get the error Authentication adapter "..." was not found. when visiting http://localhost/Project/example/user-manager/users :(
Does anyone have any clue of what I might be missing?
The problem was that the php function class_exists(...) didn't recognise the custom authentication class, so after digging a bit more I realised that the namespace shown in the docs only works for a custom authentication file defined in the App environment, but not in the Plugin one (silly me).
So I changed namespace App\Auth; to namespace Example\UserManager\Auth; inside ExampleAuthenticate.php and it worked like a charm! now the function class_exists('Example\\UserManager\\Auth\\ExampleAuthenticate') returns true and everything works perfect by defining Example/UserManager.Example in the authenticate config params.

Unable to use Laravel / Socialite with Lumen

I try to use the package Laravel\Socialite in my system in Lumen (5.1)
I added this in the config\services.php file :
<?php
//Socialite
'facebook' => [
'client_id' => '##################',
'client_secret' => '##################',
'redirect' => 'http://local.dev/admin/facebook/callback',
],
In bootstrap\app.php file :
class_alias(Laravel\Socialite\Facades\Socialite::class, 'Socialite');
$app->register(Laravel\Socialite\SocialiteServiceProvider::class);
Then I created a controller for the facebook authentication :
<?php
namespace App\Http\Controllers\Facebook;
use App\Http\Controllers\Controller;
use Laravel\Socialite\Contracts\Factory as Socialite;
class FacebookController extends Controller
{
public function redirectToProviderAdmin()
{
return Socialite::driver('facebook')->scopes(['manage_pages', 'publish_actions'])->redirect();
}
public function handleProviderCallbackAdmin()
{
$user = Socialite::driver('facebook')->user();
}
}
And in the routes.php :
$app->get('/admin/facebook/login', 'App\Http\Controllers\Facebook\FacebookController#redirectToProviderAdmin');
$app->get('/admin/facebook/callback', 'App\Http\Controllers\Facebook\FacebookController#handleProviderCallbackAdmin');
I just followed the documentation, changing according to my needs. When I go to page http://local.dev/admin/facebook/login, I get the following error :
Non-static method Laravel\Socialite\Contracts\Factory::driver() cannot be called statically, assuming $this from incompatible context
Indeed, according to the code, driver function must be instanciate.
EDIT : And if I try to instanciate this class, I get the following error :
Cannot instantiate interface Laravel\Socialite\Contracts\Factory
How do you make this module to work?
here's how that works in my case
in services.php file
'facebook' => [
'client_id' => '***************',
'client_secret' => '***************',
'redirect' => ""
],
i left redirect empty cause my site is multilingual (so, it fills in a bit later with sessions). if you use only one language, put there your callback absolute path. for example
"http://example.com:8000/my-callback/";
also check your config/app.php. in providers array
Laravel\Socialite\SocialiteServiceProvider::class,
in aliases array
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
my routes look like this
Route::get('facebook', 'Auth\AuthController#redirectToProvider');
Route::get('callback', 'Auth\AuthController#handleProviderCallback');
here's auth controllers methods. put in top
use Socialite;
//იობანი როტ
public function redirectToProvider(Request $request)
{
return Socialite::with('facebook')->redirect();
}
public function handleProviderCallback(Request $request)
{
//here you hadle input user data
$user = Socialite::with('facebook')->user();
}
my facebook app
giga.com:8000 is my localhost (so its the same localhost:8000)
as you can see in Valid OAuth redirect URI, you should put there your callback. in my case i use three urls cause i have three languages. in your case it should be just
http://your-domain-name.com:8000/callback
if you work on localhost, you should name your domain in config/services.php
mine look like this
'domain' => "your-domain.com",
after everything run these commands
php artisan cache:clear
php artisan view:clear
composer dump-autoload
restart your server, clear your browser cookies. hope it helps

Categories