Type error: Argument 1 passed to Jenssegers\Mongodb\Query\Builder::__construct() must be an instance of Jenssegers\Mongodb\Connection - mongodb

An application which is written in Laravel using mondodb as backend where "jenssegers/laravel-mongodb" vendor used as interface. Post loading application in browser throws following error :
Type error: Argument 1 passed to
Jenssegers\Mongodb\Query\Builder::__construct() must be an instance of
Jenssegers\Mongodb\Connection, instance of
Illuminate\Database\MySqlConnection given

Solution which helped me :
In .env file which overrides the config files.
it had DB_CONNECTION=mysql.
Changing it to following, fixed this bug.
DB_CONNECTION=mongodb
Work of caution :
Please ensure to provide correct value based on your server setup for following .env variable, I've kept it as default.
DB_CONNECTION=mongodb
DB_HOST=127.0.0.1
DB_PORT=27017
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=

if using two database connection together and have this problem with passport
modify setting in this Path:
vendor/laravel/passport/config/passport.php
and then change this lines:
'storage' => [
'database' => [
'connection' => env('DB_CONNECTION', 'yourdb'),
],
],

Related

Circular reference detected on TYPO3 11 backend login page

I have a weird error when trying to call the TYPO3 11 backend login page.
I updated from TYPO3 10 and can't login anymore.
I already removed all of my custom extensions, but the error persists and I can't make out where it comes from or why.
It seems to crash when reaching the first f:form.hidden field of the default login Fluid template.
As this is an obvious issue that probably would have got caught by core devs, I am pretty sure that this is correlated to a configuration of my instance, but as I said, this is to weird of an issue for me and I have no idea where to dig for the issue.
This is error message:
I can provide the whole stacktrace if needed.
Did you update your .htaccess file with the new rules for the TYPO3 backend? You can find a sample file in the the Resources folder of install tool extension: typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/root-htaccess
And I assume that you cleared all caches in the install tool and did a composer dump-autoload.
I discovered the source of this issue.
I had the following configuration automatically generated in my LocalConfiguration.php.
'SC_OPTIONS' => [
'GLOBAL' => [
'softRefParser' => [
'email' => 'TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex',
'ext_fileref' => 'TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex',
'notify' => 'TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex',
'substitute' => 'TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex',
'typolink' => 'TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex',
'typolink_tag' => 'TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex',
'url' => 'TYPO3\\CMS\\Core\\Database\\SoftReferenceIndex',
],
],
...
This caused the above error message. After removing this part from my configuration, the system lets me login and works flawlessly.

Why I get 500 Error while on XAMPP while loading CodeIgniter 3 database library?

I have gone through number of threads on stackoverflow and on other forums to find the answer but could not find relevant answer. People have applied different approaches but none has worked for me thus far.
I am using CI 3 on XAMPP and whenever I load database library in the model, I run into 500 Error.
Here is my CI database config info:
'hostname' => 'localhost',
'username' => 'my_user',
'password' => 'my_pass',
'database' => 'prod_db',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
PHP ini db libraries are as below:
extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
;extension=php_ftp.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll ; Must be after mbstring as it depends on it
extension=php_mysqli.dll
;extension=php_oci8_12c.dll ; Use with Oracle Database 12c Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll
My model code is as below:
class loginmodel extends CI_Model {
public function validate_login($username, $password) {
$this->load->database();
$var = 0;
return $var;
}
}
Whenever I remove $this->load->database(); from the model, my code runs and i am able to redirect to a "Login Failed" page. BUT, whenever I load my database library in autoload.php or load it in above model, code fails.
Autoload.php
$autoload['libraries'] = array('database');
Apache error logs showed below errors but I could not figure as why this was happening.
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_mysqli.dll' - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_pdo_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0
Please advise.
EDIT:
I verified all config to be OK and as stated in the comments, I added environment variables to windows and verified through PHPInfo that mysqli and mysqlnd were loaded.
Despite getting all the config right, error still persisted and I did a clean install of CI to reproduce library load failure. This time CI returned an error that db access was denied.
I then realized that after migration, database user was not created in the new environment. So once I created the desired user and assigned it required privileges, I was able to run the code just fine.
Therefore, if anyone encounters such issue in future, below steps might help:
First and foremost, verify if your desired user can access the
database.
Modify your .htaccess to use your desired URL schemes only after
verifying that database connection is working
Then verify that absolute path is available in PHP.ini on XAMPP.
Plus, verify that PHP is added in the environment variables. My
Values on Windows 10 are as follows: Variable Name: PHP , Variable
Value: C:\xampp\php\ext
In CI, mysqli is selected as database driver
In PHP.ini mysqli extension is enabled. i.e. php_mysqli.dll
Echo PHPInfo to verify that mysqli and mysqlnd are available in your
installation.
If nothing works, do a clean install of CI on a separate directory and load database library after setting up your database configuration and before setting up .htaccess until you can reproduce the error.
Hope that error will be eliminated!

Failed to parse address on mysqli_connect

Background: Converted from EasyApache3 -> EasyApache4 (Cpanel). Went from mpm-prefork/php5.5/dso to mpm-worker/php71fpm/fastcgi.
The error message is:
Failed to parse address "127.0.0.1:3306:3306" in /home/user/conndb/conndb.php on line 2
The code is:
<?php
$con = mysqli_connect('127.0.0.1:3306','user','password','database');
?>
I had done a previous test of this configuration on a test server with no issues - so puzzled that I ran into this in production. Tried changing to localhost but no difference. Had to revert back to EasyApache3 config.
I'm stumped. Notice the port is repeated twice in the error message. I wonder if this version of mysqli is 'smart' enough to know to put in 3306 itself and then chokes when it's explicitly coded?
Closing the question.... confirmed that removing the :3306 port corrected the issue. Obviously a change php5.5 to php7.1. I'm not sure how you'd deal with a non-standard mysql port - but not an issue for me.
According to PHP documentation if using non-standard port you must pass it as a fifth parameter -
// change the last parameter to whatever your DB port is
$con = mysqli_connect('127.0.0.1' 'username', 'password', 'database', 3306);
And by "non-standard port" is meant everything, different by the result of
echo ini_get("mysqli.default_port");
because this is the default value of this parameter.
The PHP documentation page - http://php.net/manual/en/mysqli.construct.php

Setting Hystrix timeout with environment variable

In order to change Hystrix's default request timeout (1000ms), one must set the following property :
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000
What is the corresponding environment variable ?
I would like to "tune" the timeout on my favorite cloud platform without touching the source code first.
I'm pretty sure this one doesn't work : HYSTRIX_COMMAND_DEFAULT_EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS=2000
EDIT : Problem was found with Spring Cloud Camden / Spring Boot 1.4.
VM options and environment variables can be referenced from application configuration, which is often a more convenient way to set properties with longer names.
For example, one can define the following reference in application.yml:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: ${service.timeout}
which will be resolved from the VM option -Dservice.timeout=10000, setting the default Hystrix command timeout to 10 seconds. It is even simpler with environment variables - thanks to relaxed binding, any of these will work (export examples are for Linux):
export service.timeout=10000
export service_timeout=10000
export SERVICE.TIMEOUT=10000
export SERVICE_TIMEOUT=10000
The common approach is to use lowercase.dot.separated for VM arguments and ALL_CAPS_WITH_UNDERSCORES for environment variables.
You could try expression with a default value:
hystrix.command.default.execution.isolation.thread.timeoutIn‌Milliseconds: ${SERVICE_TIMEOUT:2000}
In case you have SERVICE_TIMEOUTsystem variable - it will be used by an application, otherwise, a default value will be picked up.
Found more of a workaround than a solution, using SPRING_APPLICATION_JSON environment variable :
SPRING_APPLICATION_JSON='{ "hystrix" : { "command" : { "default" : { "execution" : { "isolation" : { "thread" : { "timeoutInMilliseconds" : 3000 } } } } } } }'
You can use Spring config yaml file , Please read further on following link
https://github.com/spring-cloud/spring-cloud-netflix/issues/321
VM option -Dhystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=2000 works for me. However it has a side effect, then you can not change the config value in java code since system properties are prioritized.
ConfigurationManager.getConfigInstance().setProperty(
"hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 3000);// it doesn't work

Yii2 Module setup in advanced template

I have created a module in frontend folder path is frontend/modules/module-name/Module.php. I am getting ReflectionException error as Class app\modules\module-name\Module does not exist. In frontend/config/main.php i have added this configuration
'modules' => [
'module-name' => [
'class' => 'app\modules\module-name\Module'
]
Can anyone help why i am getting this ReflectionException error
You said that you are using an advanced template, folder path is frontend/modules/module-name/Module.php, but you are requiring app\modules\module-name\Module class. It looks like a namespace from basic application template.
In case of advanced template, make sure that Module.php file is in frontend/modules/module-name folder, has a namespace frontend\modules\module-name and you are requiring frontend\modules\module-name\Module class.