Using "Legacy" MongoDB Driver with PHP7 - mongodb

Is there a way to use the Legacy Mongo PHP Driver from PECL with PHP7? Maybe unofficial fork with PHP7 support or compile/modification instruction...

There is an alternative if you really need to use any bundle or library with strong dependencies on php mongo legacy driver, it's called "alcaeus:mongo-php-adapter". It provides an ext-mongo library on top of mongo-php-library (sic).
https://github.com/alcaeus/mongo-php-adapter
If you face any problem with composer related with the absence of legacy driver (Famous message "The requested PHP extension ext-mongo * is missing") you can fix it adding that to composer.json
"provide": {
"ext-mongo": "1.6.12"
},
In this case may be you want to take a look to this thread (same situation but with heroku): https://github.com/alcaeus/mongo-php-adapter/issues/67

No, the legacy driver does not support PHP7. Here's the commit and the JIRA Ticket where this was officially finalized.
The new PHP MongoDB driver can be found in PECL here (or GitHub).
To install, just:
pecl channel-update pecl.php.net
pecl install mongodb
echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
The documentation for the new driver can be found here. I'd like to include a note from the documentation:
Ultimately, this extension is not intended to be used alone. Users should considering using this driver alongside one or more userland PHP libraries, such as mongo-php-library.
The new mongodb driver / PHP extension is a lot more low-level than the legacy mongo driver, and you are encouraged to use a higher-level library on top of the driver rather than using it directly in your code.
The Mongo PHP Library (releases) is the official high-level library for PHP, and it's what is recommended to use in your projects. It's still in Beta, but this still seems to be the safest and most-future-proof path forward with PHP7.
Edit: The Legacy Mongo Driver is no longer active at all.

Related

db.listCollections() does not work in mongodb6.0.3

I used mongodb version < 4. Now I needed to install mongodb on ubuntu 22, the easiest way was to install version 6.0.3
But now some of the functionality does not work, for example
db.listCollections()
-There were no problems, but after upgrading to mongodb6.0.3 - it does not work. I read that it is advised to use
db.getCollectionNames()
Are these functions interchangeable? Is there no difference between them?
And is it possible to make db.listCollections() work in version 6.0.3?
I read here that many functions are already outdated in version 5
db.listCollections() was a convenience wrapper in the legacy shell.
To get the same behavior in mongosh, use the listCollections database command, like
db.runCommand("listCollections")

Troubleshooting PostgreSQL performance issue

I have a data ware house running on PostgreSQL and I would like to check what all are the missing indices are in my database.
I tried to install the extension pg_qualstats but it is giving the below error.
root#Ubuntu-1604-xenial-64-minimal ~ # sudo pip install pg_qualstats
Collecting pg_qualstats
Could not find a version that satisfies the requirement pg_qualstats (from versions: )
No matching distribution found for pg_qualstats
You are using pip version 18.1, however version 19.2.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root#Ubuntu-1604-xenial-64-minimal ~ #
So how can i install this extension? I tried the CREATE EXTENSION pg_qualstats but it was giving error.
Also is there any other database maintenance need to be done for the database regularly?
What all parameter I have to check?
Can we automate the maintenance activity?
I was a SQL server DB admin and it was much easier to find out the missing index, understand the execution plan, DB maintenance but I find it hard, when it comes to PostgreSQL.
So any guidance will be of great help.
I am only answering the immediate question regarding the installation of pg_qualstats - the rest of the questions are way too broad for a platform like stackoverflow (or dba.stackexchange).
Many interesting extensions are provided as source code in Postgres (that's one of the reasons why it's highly recommended to run Postgres on Linux, because compiling the extensions is way easier in Linux than it is on Windows, and may extensions are only developed for Linux).
pg_qualstats is no different.
It is provided together with PoWA and the installation of the extension is documented as part of their installation guide
In a nutshell:
Download the source:
wget https://github.com/powa-team/pg_qualstats/archive/1.0.7.tar.gz -O pg_qualstats-1.0.7.tar.gz
tar zxvf pg_qualstats-1.0.7.tar.gz
cd pg_qualstats-1.0.7
the compile it:
make
make install
Register the shared libraries by editing postgresql.conf and after restarting Postgres the extension can be created using CREATE EXTENSION pg_qualstats;

How to install Mongodb PHP extension in Ubuntu 16.04 LTS

I'm running Ubuntu 16.04 LTS and I want to use Mongodb with PHP. For this I thought that sudo apt-get install php5-mongo (which is enough for Ubuntu 14.04 LTS) would be enough but I was wrong. I'm getting error like this E: Unable to locate package php5-mongo.
I've just upgraded to Ubuntu 16.04 LTS and want to use mongodb with PHP. Running PHP version is PHP Version 7.0.4-7ubuntu2.
So what can I do to solve this?
I'm afraid you are a bit out of luck at the moment. The current situation is that there are two MongoDB extensions:
"php-mongo", which is the "old" one; This extension supports up to PHP 5.*, but not PHP7. Only bug fixes are planned for it;
"php-mongodb", which is the "new" one; This extension supports PHP5 as well as PHP7;
Now the problem is that the new one is not compatible with the old one, as their whole internals are completely different. Unfortunately there are very few places where examples using the new one's syntax is used, as absolute majority of Mongo-related code is written using the old extension.
As it stands at the moment, if you have moved on to PHP7 your only option is to use the "new" extension, which in turn means that your previous code will stop working.
I've seen couple attempts to create a polyfill for making the migration those two possible (example: https://github.com/alcaeus/mongo-php-adapter), however as I haven't tried it myself I can't tell how well it works.
It seems that this library http://mongodb.github.io/mongo-php-library/ is supposed to cover the gap - after giving it a shot I believe it should cover majority of the "old" functionality without updating code too much.
If some of you are still wondering to use a simple wrapper to the new library as said in this answer: https://stackoverflow.com/a/48086676/2569789
I'm maintaining one for this purpose and you can find it here: https://github.com/ThomasSquall/PHP7MongoDriver
It covers just a few methods at the today's date but I'm going to improve it constantly and I hope would like to contribute too :)

Installing PHP 7.0.0RC2 with mysqli on Raspberry Pi B

Last week I installed PHP 7.0.0RC2 on my Raspberry Pi B.
I am able to view PHP pages, however, the problem is that I cannot connect to the database using mysqli (I know that mysql is no longer supported in PHP v7).
I ran the ./configure command with --with-mysqli=shared.
However, when I check which modules are installed using the php -m command, I do not see mysqli.
I tried adding extension=mysqli.so to the php.ini file.
It first complained that the mysqli.so file could not be found, so I tried copying the mysqli.so of my php5 version to the extensions folder.
However, this did not solve the problem and resulted in the following error message:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20141001/mysqli.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20141001/mysqli.so: undefined symbol: zval_used_for_init in Unknown on line 0
Does anyone got any suggestions of how to get mysqli to work with my PHP7 installation on my Raspberry Pi?
You may find detailed information in the configure output, but it's pretty hard to catch, and if it's not a fatal error, won't stop the build going ahead when you make.
The recommended (read: only decent) driver for MySQLi is the MySQL Native Driver (mysqlnd).
If you want MySQLi to be built shared, you must also build mysqlnd shared, and everything that depends on it (PDO MySQL, for example).
It's going to be simpler to just build the native drivers static, using the configure option:
--with-mysqli=mysqlnd
Which will enable a static build of mysqlnd and mysqli.
If for some reason you really do want to build shared, then you'll need configure options that closely resemble, if not are exactly the same as:
--enable-mysqlnd=shared
--with-mysqli=shared,mysqlnd
Which will result in a shared build of mysqlnd and mysqli, requiring you to add extension=mysqlnd.so and extension=mysqli.so in the appropriate order (the latter depends on the former), in the appropriate place.
Remember to make distclean before you re-configure the build, surprising things will happen if you do not ;)

Is pg_test_fsync contrib module in postgresql 9.2 deprecated?

I have installed postgresql 9.2.4 on my machine with Ubuntu 12.04.1 LTS. Based on this documentation page (http://www.postgresql.org/docs/9.2/static/pgtestfsync.html), it seems *pg_test_fsync* contrib module is part of postgresql 9.2.4 . But when I checked *pg_available_extensions* system view and also the following location on my system /usr/share/postgresql/9.2/extension, I could not find this module. It seems to be missing even in the contrib documentation here (http://packages.debian.org/experimental/postgresql-contrib-9.2).
Am I missing something? Could anyone guide me on how can I test 'pg_test_fsync' on postgresql 9.2.4 ?
Thanks.
The manual page you link to is for a command-line tool, not a function which runs inside the database itself, so will not show up when interrogating system views for available extensions.
Although the Debian package description doesn't mention it, the list of files included does. The list includes both /usr/lib/postgresql/9.2/bin/pg_test_fsync and /usr/share/postgresql/9.2/man/man1/pg_test_fsync.1.gz, so once that package is installed, you should be able to type man pg_test_fsync to confirm the options supported.