Attempting to use index type '-1' where index types are not allowed (1 or -1 only) - php

I am using:
$db->collection->find()->sort(array('username' => '-1'));
And I keep getting the error:
MongoCursorException: localhost:27017: Attempting to use index type
'-1' where index types are not allowed (1 or -1 only).
I am using MongoDB 2.4.1 with PHP driver 1.3.x.
Why is this?

You have called sort like so:
sort(array('username' => '-1'));
Which is a problem. In MongoDB 2.4.1 there is a slight quirk (bug?) which means that it will not accept strings any more for sort ordering.
Since this is not in the driver but instead in the server (MongoDB itself) simply changing driver version will not fix this.
This could have existed earlier than MongoDB 2.4.1 however, I merely tested this on MongoDB 2.0.0 and 2.1.x whereby I did not observe this behaviour on the same PHP driver version (1.2.x and 1.3.x).
To fix this you must specify a signed numerical figure like so:
sort(array('username' => -1));
That will work.
Edit
After posting in the mongodb-user Google group, I found out this was not a bug, however, it is still something to be aware of.

Related

Elasticsearch\RuntimeException: Failed to JSON encode: 5 in file /Elasticsearch/Serializers/SmartSerializer.php on line 33

I am trying to run a project that uses elasticsearch on my computer. But at the point that the API. Queries something from elasticsearch I get the following error and the query does not execute:
Elasticsearch\Common\Exceptions\RuntimeException: Failed to JSON encode: 5 in file /Users/sobhan.bagheri/projects/laravel/regionsdelen-api/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Serializers/SmartSerializer.php on line 33
I am using: laravel framework with valet - php7.1 - elasticsearch 6.1.2 - and elasticsearch/elasticsearch:v6.0.1 for the driver.
I tried everything like changing elasticsearch to newer or older versions. Changing the way of the client connects to elasticsearch and also changed versions of the elasticsearch/elasticsearch driver but nothing seems to work.
btw: those versions I mentioned are the exact ones running on another machine without this error.
P.S: This error only occurres when I query a swedish character.
I also was facing the same problem. For me, the issue was that string contained special character which creates an issue while encoding to JSON so try this.
$array= array_map('utf8_encode', $array);
Hopefully, this will work for you.
I had the same problem, my problem was due to using substr() function on strings before inserting in elasticSearch index then I replaced it with mb_substr(string, start, length,'utf8') function and the problem solved.

Error and warning connecting MongoDB to PHP using php_mongodb extension

I installed the MongoDB PHP driver on Windows 10 (I'm using WAMP equipped with PHP 5.6.25. following the istructions I found at http://php.net/manual/en/mongodb.installation.windows.php and I installed also the libbson and libmongoc libraries (requested as requirements) as written at http://php.net/manual/en/mongodb.requirements.php.
Then, I added the bin folders of MongoDB, libbson and libmongoc to system path.
However, even if I can see the php_mongodb extension in the extensions list of WAMP, launching phpinfo() the mongo extension doesn't appear with the others.
Furthermore, tryng to connect to my database with
<?php
$mongo=new MongoClient("");
$db=$mongo->galileo;
$collection= $db->items;
print_r("Number of documens: "); ?>
I got the error
Fatal error: Class 'MongoClient' not found in C:\wamp64\www\galileo\index.php >on line 21
At a first look, reading this error, it might seem like that PHP is looking for php_mongodb extension in the uncorrect folder i.e. C:\wamp64\www\galileo\index.php (where the index page of my project is placed) instead of the correct one C:\wamp64\bin\php\php5.6.25\ext where all the extensions are.
But, looking at php log file php_error.log I find also a warning that says:
PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php5.6.25/ext/php_mongodb.dll' - Il sistema operativo non pu� eseguire %1.
in Unknown on line 0.
(for not Italian speaking, the phrase after - means the operating system can't execute %1, even if I can't imagine what %1 stands for).
Even using the new class MongoDB\Driver\Manager I get the error
Fatal error: Class 'MongoDB\Driver\Manager' not found in C:\wamp64\www\galileo\index.php on line 21
and the same warning.
Do you notice some error or forgetfulness in the installation process as I described and, if not, do you know how to fix the problem?
The problem is certainly related to WAMP and I think is related to the multiple php.ini in his folders. In fact, in the apache folder you can find a php.ini file that cannot be modified, otherwise nothing works at all; at the same time any changes made to the php.ini file in the php folder seems have no effect except making appear the mongodb extension in the extensions list.
So, I try using XAMPP, as suggested in this video tutorial and it works. Using Composer I was able to install also the PHP library and not only the driver.
you should not use 'MongoClient class' anymore, this extension that defines this class is deprecated. look at here.
instead, you should use MongoDB\Driver\Manager class. please read http://php.net/manual/en/class.mongodb-driver-manager.php.
and the setup must be like this in php:
$mongo = new MongoDB\Driver\Manager("mongodb://localhost:27017");
And if you still use the old class; you either need to install the old legacy extension (pecl install mongo) and use PHP 5.x, or update your code to use this new driver's classes as the old driver is not available for PHP 7. There is an upgrade guide at here.
the last part is from derickr's answer in this issue on github: https://github.com/mongodb/mongo-php-driver/issues/300

Fatal error: Call to undefined function httppost()

I am trying to make a project work. But I am getting an error like this:
Class 'App' not found in /var/www/html/project/test.php on line 4
line 4 of this file says:
app::$activepage = $_GET['_page'] ? httpget('_page') : $_POST['_page'] ? httppost('_page') : 0);
I am using cakePhp Version: 1.3.15-1.
The weird thing is that when I do apt show cakephp it says State: not installed
However, I have followed all the instructions of https://www.digitalocean.com/community/tutorials/how-to-install-cakephp-on-an-ubuntu-12-04-vps and when I open the index.php file of cakephp, it doesn't indicate any errors.
As I said in my Comment:
Your snippet / folder structure doesn't look like CakePHP.
Part of the problem may be a version mismatch. You say you're using version 1.3.15, but the tutorial on installing it that you link was created over a year later and references version 2.3.9. It looks like the general steps are the same, based on comparing your tutorial to the steps in the 2.X blog tutorial. You might have more luck with an older tutorial on using CakePHP on Ubuntu. Most of the steps look similar, but there are some differences with the .htaccess portion that could be causing the problem. Neither the 1.3 or 2.3 versions look like they require any "installing."
If you're not looking at the older version for any particular reason, of course it's best to use the most recent version of CakePHP, but I assume you have a particular reason for using that version. But if you're stuck, you might try a newer version to see if it gives the same errors.

Array index changes case when connecting to MySQL on Windows, but not on Linux

When I connect my local working copy (Windows 7, WAMP, Apache 2.2, MySQL 5.1, PHP 5.3, CakePHP 2.4) to the local MySQL database, it gives me the following error:
Notice (8): Undefined index: Asset [APP\Controller\AssetsController.php, line 241]
Note, when connecting to the remote RHEL MySQL 5.1 server, the issue does not present itself.
Code in question:
Line 241: 'EnvironmentDeploymentStatus.asset_id'=>$conf['Asset']['asset_id'],
When connected to the RHEL MySQL 5.1, doing var_dump($conf), I'll get this:
array (size=3)
'Asset' =>
array (size=6)
When connected to the localhost Windows MySQL 5.1, doing var_dump($conf), I'll get this (notice the case change in the array key):
array (size=3)
'asset' =>
array (size=6)
The view that populates $conf contains this:
...
from
(((((((`assets` `asset`
...
I put in the following configuration in my local MySQL's my.ini file:
lower_case_table_names=2
The tables are already in lower case (and meet CakePHP standards), I don't think this has any impact on what I'm doing however.
the lower_case_table_names = 2 is probably your problem. It says in the docs
This option also applies to database names and table aliases.
(emphasis added)
MySQL Doc on lower_case_table_names
Which means MySQL is changing the table alias provided by Cake to its lowercase version.
The solution is to set this value back to recommended value of 1.

Load *LIBL (library list) defined in CRTJOBD when connecting to db2 with PDO

It seems nobody had this problem yet.... With db2_connect I found docs that decrible how to load a default library list (*LIBL) on connection but with PDO nothing!
I'd like to perform statements without specifing always the library name in front of file name. I already created a JOB DESCRIPTION to load the libraries, and when I log in with the PC5250 emulator those library are online.
But if I run a query with PDO without specifying the library name following is returned:
Error executing sth in testGet for AS400 SQLSTATE[42S02]:
Base table or view not found: 0
[IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0204 -
TESTFILE in WEB type *FILE not found.
(SQLPrepare[0] at ext\pdo_odbc\odbc_driver.c:206)
To use the library list, you will need to make sure your connection attributes specify system naming, and I would avoid setting a current schema.
Without much knowledge of PHP + PDO, the stackoveflow tag wiki gives a good introduction. Check that PDO is configured for proper settings for DB2 for i, not LUW or z. Likewise check db2_connect settings. (Why are you using that, instead of straight ODBC?)
I know it's been awhile since you posted but I came across some info on how to do library lists using the PDO driver... see http://yips.idevcloud.com/wiki/index.php/XMLSERVICE/PHPPDOChangeLog.
So for example you could do something like this:
$options = [
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_AUTOCOMMIT => true,
PDO::I5_ATTR_DBC_SYS_NAMING => true,
PDO::I5_ATTR_DBC_LIBL => "LIB1 LIB2 LIB3",
];
$db = new PDO("ibm:SYSTEM", "user", "password", $options);
Keep in mind this will probably require a recent Zend Server (since Dec 2014). I know the latest stuff is in the new ZS 8.5 but I'm not sure about older releases.
You might also be able to leave off the library list option - in my limited testing this appears to let it use the library list from the job description. I'm not sure about the current library and YMMV but I'd be curious to hear back if it works for you or not.
Also for what it's worth an email address for the official maintainer is listed on http://pecl.php.net/package/PDO_IBM. Questions could also be sent to the WEB400 mailing list (http://lists.midrange.com/mailman/listinfo/web400), I think people who are involved in the development of the pdo_ibm driver are on there as well.
If you're talking about these docs, then that is if you're using PDO_IBM on IBM i. I don't think those settings are supported on any other platform. From your error message, it seems that you are using the IBM i Access ODBC driver through PDO_ODBC. The IBM i Access ODBC driver connects to a QZDASOINIT prestart job running in QUSRSYS subsystem. If you want those jobs to use a different job description, you need to use CHGPJE to change it: CHGPJE SBSD(QUSRSYS) PGM(QSYS/QZDASOINIT) JOBD(MYLIB/MYJOBD). If you're using SSL connections, also change QZDASSINIT jobs. You'll need to end any existing QZDASOINIT/QZDASSINIT jobs and the new pre-start jobs will pick up the new settings. Note that this will affect all ODBC, JDBC, OLEDB, .NET connections for IBM i Access drivers.
You can configure the library list through the DSN as well, by setting the DBQ connection string or DefaultLibraries ODBC.INI setting or setting the "Library List" value under the Server tab from the DSN configuration GUI on Windows.

Categories