Laravel oracle connection

By ukmodak | March 31st 2024 10:38:02 AM | viewed 662 times
Install oracle extension in xampp server by the following instruction

XAMPP is an open source package that contains Apache, PHP and many PHP 'extensions'. One of these extension is PHP OCI8 which connects to Oracle Database

Visit http://localhost/dashboard/phpinfo.php via your browser to see the architecture and thread safety mode of the installed PHP. Please note this is the architecture of the installed PHP and not the architecture of your machine. It’s possible to run a x86 PHP on an x64 machine.

Oracle OCI8 is pre-installed in XAMPP but if you need a newer version you can download an updated OCI8 PECL package from pecl.php.net. Pick an OCI8 release and select the DLL according to the architecture and thread safety mode. For example, if PHP is x86 and thread safety enabled, download "7.2 Thread Safe (TS) x86". Then replace "D:\xampp\php\ext\php_oci8_12c.dll" with the new "php_oci8_12c.dll" from the OCI8 PECL package.

Edit "D:\xampp\php\php.ini" and uncomment the line "extension=oci8_12c". Make sure "extension_dir" is set to the directory containing the PHP extension DLLs. For example

 extension=D:\xampp_726\php\ext\php_oci8.dll
 

Download the Oracle Instant Client Basic package from OTN. and Select the correct architecture to align with PHP's. For Windows x86 download "instantclient-basic-nt-12.2.0.1.0.zip" from the Windows 32-bit page.

Extract the file in a directory such as "D:\Oracle". A subdirectory "D:\Oracle\instantclient_12_2" will be created. Add this subdirectory to the PATH environment variable. You can update PATH in Control Panel -> System -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables -> PATH. In my example I set it to "D:\Oracle\instantclient_12_2".

Restart the Apache server and check the phpinfo.php page again. It shows the OCI8 extension is loaded successfully.

If you also run PHP from a terminal window, make sure to close and reopen the terminal to get the updated PATH value.

Install essential library in laravel 7.x

run the following command to install library

 D:\xampp_726\htdocs\ptmc > omposer require yajra/laravel-oci8:"7.*"
in config/app.php  add 

 => provider 
   Yajra\Oci8\Oci8ServiceProvider::class,

Run the command

 D:\xampp_726\htdocs\ptmc >php artisan vendor:publish --tag=oracle

Open a model and add the following code

use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Notifications\Notifiable;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

	use Authenticatable, CanResetPassword, Notifiable;


        protected $table = 'users';
        public $timestamps = false;
        protected $fillable = ['id','first_name','last_name','user_name','employee_id','full_name','designation_id','department_id','sbu_id','unit_id', 'email','mobile','password','remember_token','active','create_date','update_date','meta_name'];
        protected $guarded = ['id'];

	    protected $hidden = ['password', 'remember_token'];
              
}

For insert ID input id number and for update ID maintain custom id nuumber

bONEandALL
Visitor

Total : 20974

Today :28

Today Visit Country :

  • Germany
  • United States
  • Singapore
  • China
  • United Kingdom
  • South Korea
  • Czechia