Wednesday, December 2, 2020

sqlite3 and pdo_sqlite not loaded in php apache2 localhost after upgrade to php 7.4 on Windows

The problem is that the two extensions php_sqlite3.dll and php_pdo_sqlite.dll are not loaded eventhough the two are exist in the extension directory, I had this problem when I upgraded php to version 7.4 and I thought the problem was in my system but after a while I found on Php.net that an additional setup on Windows is required as of PHP 7.4.0.

Note: Additional setup on Windows as of PHP 7.4.0

In order for this extension to work, there are DLL files that must be available to the Windows system PATH. For information on how to do this, see the FAQ entitled "How do I add my PHP directory to the PATH on Windows". Although copying DLL files from the PHP folder into the Windows system directory also works (because the system directory is by default in the system's PATH), this is not recommended. This extension requires the following files to be in the PATH: libsqlite3.dll.

 That is great, but putting this file in the system path seems not a good practice , so it is better to copy this file to the Apache BIN folder, and you will not be worry about sqlite3 extension again unless a new version of libsqlite3.dll library released.

Monday, March 2, 2020

Audio files MP3 not working on whatsapp

Audio Files on Whatsapp Application has a special audio format which is called opus , and if you want to upload an audio file to Whatsapp web , you have to choose through the upload window which media you will use: Camera , Album Folder , Document or Contact.
Just use the Document option when you want to upload your mp3 file.

For more technical details about this subject you can visit this  Thread

Tuesday, June 11, 2019

laravel Chunk without "id" column in Sqlite database

When you have to retrieve large data from a database table and want to process through it , In Laravel using Eloquent ORM or Query Builder, (Query Builder is preferred in this case for performance reasons), there is a very nice method called "Chunk" , this method requires primary key  column to be exist on the table .
From Laravel Documentation :
If you need to work with thousands of database records, consider using the chunk method. This method retrieves a small chunk of the results at a time and feeds each chunk into a Closure for processing

So, if you have a table without and Id column in it, then you cannot use this method unless you have it with another name ,if so, then you have to add this as a variable in the eloquent model :

protected $primaryKey = "theIdColumnaName";

In Sqlite databases, fortunately any table has its own id column without creating it Called "rowid" , what you need to do is to assure you have added the right property "primaryKey" to the model as given below:

protected $primaryKey = "rowid";

Then you can enjoy chunking :)

 $capsule->getConnection('sqlite')->table('users')->orderBy('rowid')->chunk(100, function ($users) {
    foreach ($users as $user) {
         echo $user->name;
        
    }
  });

Monday, August 13, 2018

Laravel Models Eloquent Dynamically change table name

Some times you need to use one model for many tables, that means you want the same model but with many tables . So the property table will be dynamically set .to achieve this all you have to do is to use a trait that do the job as shown in the following code:

 

 /* DynamicTable.php */ 
 
trait DynamicTable
{
    protected $connection = null;
    protected $table = null;

    public function bind(string $connection, string $table)
    {
        $this->setConnection($connection);
        $this->setTable($table);
    }

    public function newInstance($attributes = [], $exists = false)
    {
        // Overridden in order to allow for late table binding.

        $model = parent::newInstance($attributes, $exists);
        $model->setTable($this->table);

        return $model;
    }

}


let's say our Model is called Profile :
require_once("DynamicTable.php"); 
 
class Profile extends Illuminate\Database\Eloquent\Model {
 
 use DynamicTable;
 
 public $timestamps = false; 
   
} 
 

Now, when you need to retrieve Model you will create a new object of this model and assign table and connection if the connection is different from default:
profiel1 = new Profile;
prfoile->setTable ("profile01");
profile->setConnection("mysql");
$results = $profile->find(123);

To insert data you can do the same .
Some retrieving commands will not work like all(), but you can use where(1,1) and it will do the job.

Saturday, July 21, 2018

Using native Nodejs Modules in Electronjs in Windows


First of All prepare package.json file to do the job and add the following script option:

rebuild": "electron-rebuild -f -w  sqlite3 

Here We are taking sqlite3 as an Example for the native Nodejs Module that we want to use it with electron App.
Install electron-rebuild :

npm install --save-dev electron-rebuild

Now,before you can compile node module to serve electron app you have to run the command :

npm install --global --production windows-build-tools

This command will install Python2.7 (Python 3 is not supported) and windows build tools . you may get this error :

events.js:183   throw er; // Unhandled 'error' event
Error: spawn powershell.exe ENOENT.

This is because the npm cannot run Powershell Command ,So to solve this error Add PowerSell Folder to the environment system variable Path:
%SystemRoot%\system32\WindowsPowerShell\v1.0

Then restart windows.

Go to this folder on your system : C:\Program Files (x86)\MSBuild

And find what folder available their.  if you have folder (14) and this folder has (Bin) folder with a file called MSBuild.exe in it , then you can use MS version 2015.
If there is a folder called (15) that has (Bin) folder with a file called MSBuild.exe in it , then you can use MS version 2017. let say you have the folder (14).then run this command :

npm config set msvs_version 2015

if you didn't choose the right msvs version you may get a dump Error which has code and errno :

npm ERR! code ELIFECYCLE
npm ERR! errno 4294967295

or ,if the version is not the right one. you may get the error :

 MSBUILD : error MSB4132 

Also Expected error is :

gyp ERR! stack Error: Can't find Python executable , you can set the PYTHON env variable
 
but this is a clear error and will disappear only after success of this command :

 npm install --global --production windows-build-tools
 

And by Adding the Python Folder to the Path variable that you have to do it by your self.

Sunday, April 22, 2018

wordpress refuse to install plugins through dashboard

WordPress showed many permission problems when we tried to install it on a fresh install of Unix -- Ubuntu 16.04, the first and most annoying problem is the plugins from WordPress.org will not install locally and the WordPress continue to complain of access problem and asking for ftp credentials.

So, to solve this issue the first thing to do is change the ownership of WordPress folder to the  www-data:

sudo chown -R www-data:www-data /var/www/html


and change the chmod for the WordPress folder to allow write and read for the wp-content folders


the most important step to avoid this problem is to add this option to wp-config.php

define('FS_METHOD', 'direct');

Here is a nice blog post which explain how to install WordPress the right way :

install-wordpress-ubuntu-16-04

Friday, April 20, 2018

Error: More than one instance of bitcore-lib found

this error was shown when I tried to run bitcored on linux after adding new service which was the bitcore wallet service , the problem happened after each sub module trying to run its own copy of bitcore-lib, the bitcore.node depends on version "bitcore-lib": "^v0.13.19", and the bitcore-wallet-service depends on version "bitcore-lib": "^v0.15.0". So we have to remove one of these dependencies from the package in order to solve this problem:

npm uninstall --prefix /mynode/node_modules/bitcore-wallet-service -S bitcore-lib