Class 'Mongo' not found in XAMPP 64-Bit Windows 10 - php

I'm trying to run the following code from on my localhost:
<?php
$dbhost = 'localhost';
$dbname = 'phpTest';
$m = new Mongo("mongodb://$dbhost");
$db = $m->$dbname;
?>
And get the error, "Fatal error: Class 'Mongo' not found in C:\xampp\htdocs\key_ratios\mongo_test.php on line 6"
MongoDB is properly installed/recognized by PHP
I've restarted Apache several times and MongoDB is running as a service. Mongo's directory path is C:\mongodb\bin. PHP is in C:\xampp\php.
The following are PATH variables: C:\xampp\php, C:\mongodb\bin, C:\Program Files (x86)\Microsoft VS Code\bin, C:\Users[redacted]\AppData\Local\atom\bin.
Any idea why I can't get PHP to connect to Mongo?
Edit: I should note that my mongodb listingin phpinfo() is not nearly as filled out as this one. Does this mean my mongodb isn't fully installed?

I was using the wrong syntax to connect. Should be (with PHPLIB):
new MongoDB\Client("mongodb://localhost:27017");
or (with just the PECL driver): new MongoDB\Driver\Manager("mongodb://localhost:27017");
The documentation is really helpful.

Related

Fatal error: Uncaught Error: Call to undefined function db2_connect()

I have some problem. I have been looking it for almost a week. I have done include ibm_db2.dll, change php version but not working. When I run the db2 query, it shows Fatal error: Uncaught Error: Call to undefined function db2_connect() in C:\laragon\www\hpc_dev\db2_conn.php:15 Stack trace: #0 C:\laragon\www\hpc_dev\index.php(3): include() #1 {main} thrown in C:\laragon\www\hpc_dev\db2_conn.php on line 15
Currently I am using php version 7.4.12 64bit (ts) using laragon in Windows 10. I also have tested using Xampp and the same problem occur. Below are my codes to connect to ibm db2:
db2_conn.php:
<?php
ini_set("display_errors", 1);
$database = 'DB2';
$user = 'xxx';
$password = 'xxx';
$hostname = 'xx.xx.xx';
$port = 60000;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
echo "Connection failed.";
}
?>
My code to show data from db2:
<?php
include("db2_conn.php");
$sql = "SELECT * FROM EMPLOYER WHERE EMPR_LOGIN_NAME = 'xxxxx'";
if ($conn)
{
$stmt = db2_exec($conn, $sql);
$row = db2_fetch_assoc($stmt);
echo $row['SECTOR_DESC'];
db2_close($conn);
}
?>
I don't know either the problem comes from db2 extension or others. Please help me.
For information, I have download the ibm db2 extension here: https://github.com/ibmdb/php_ibm_db2
Thanks
Your question omits details of the command-lines and actions you performed.
Most likely you missed a step in the configuration.
Remember to open the laragon terminal and verify that the Db2 driver is loaded:
php -m | grep ibm
should return ibm_db2 if you have correctly configured the correct version of the extension.
If you do not see that the ibm_db2 extension is loaded then any db2_connect will fail until you resolve the missing module.
For information the current laragon_full (November 2020) delivers PHP 7.2 TS, and that works correctly with the php_ibm_db2.dll TS for v7.2.x "out of the box" (which you must first download and configure).
Additionally, if I upgrade the PHP version for laragon to PHP 7.4.12 TS, and subsequently download and configure the matching php_ibm_db2.dll TS for php v7.4.x, then it all "just works" without any issues on Win 10 x64 2020 to connect to Db2-LUW and run queries etc.
It helps to verify that your Db2 client is correctly configured. You can do that independently of PHP. If you are using the clidriver Db2-client (the smallest footprint driver) you can configure the db2dsdriver.cfg XML file and then run db2cli validate -connect -dsn -user ... -passwd ... to verify that the connection works. If you are using either the Db2-runtime-client or the Db2 full client, or a local Db2-server, you can run (in the laragon terminal):
(after configuring your Db2 node directory and Db2 db directory via appropriate configuration commands )::
set DB2CLP=**$$**
db2 connect to $yourdsn user ... using ...

I have Oracle 11.2.0.2.0 version but in xampp php folder I have older version's extension

I have installed an older version of Oracle but in xampp PHP folder I have extension oci8_12 that is why I am having error when I try to connect to DB is there any way to use this function.
And also database is created with older version 11 can I access database with newer version.
<?php
$DB = '//http://127.0.0.1:8080/apex';
$DB_USER = 'SYSTEM';
$DB_PASS = 'root';
$DB_CHAR = 'AL32UTF8';
echo 'Hello World';
$conn = oci_connect($DB_USER, $DB_PASS, $DB);
?>
Hello World
Fatal error: Call to undefined function oci_connect() in C:\xampp\htdocs\shani\shobi.php on line 15
First you have to check if the extension is loaded. You need a special version for every PHP Version. Otherwise you can't load the extension. So first check your extension version.
But i think your version is not correct and your extension is not loaded.
On Windows you need a TS-Version (Thread safe) otherwise its not working.

Class 'MongoClient' not found in xampp

I want to connect mongodb with php.
PHP version : 5.6
Mongodb:
System : 64 bit
Xampp : v3.2.1
Window : 7
I have added php_mongo.dll (as per system 64 bit) into php.ini file and copied that dll into php/ext folder.when i am trying to connect, i am getting following message.
Fatal error: Class 'MongoClient' not found in D:\xampp\htdocs\
connection file
<?php
$MongoDBConnection = new MongoClient();
$DB = $MongoDBConnection->selectDB('SimpleCrud');
$pessoas = $DB->pessoas;
?>
To use MongoDB with PHP, you need to use MongoDB PHP driver. CLICKHERE to download the driver. Make sure to download the latest release of it. Now unzip the archive and put php_mongo.dll in your PHP extension directory ("C:\xampp\php\ext" by default) and add the following line to your php.ini file.
extension = php_mongo.dll
Following is the code snippet to connect to the database :
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->myTestdb; // myTestdb-> Your Database Name
echo "Database myTestdbselected";
?>
When the program is executed, it will produce the following result −
Connection to database successfully
Database myTestdb selected

Class 'MongoClient' not found, while php connecting to mongodb in ubuntu

I installed mongodb version 3.0.7 in xampp, and installed php driver also. below is the php code to connect mongodb.
<?php
// connect
$m = new MongoClient();
// select a database
$db = $m->test;
?>
While I run this code in my localhost I am getting this error
Fatal error: Class 'MongoClient' not found in /opt/lampp/htdocs/mongo.php on line 3
<?php
// connect
$m = new MongoClient();
// select a database
$db = $m->test;
?>
This above code working fine, In xampp server you must include "extension=mongo.so" in php.ini file at usr/lib/php5/20121212/php.ini with same extension. After all setting restart your server.

Connect PHP to AS400 with ODBC or DB2

I'm trying to connect my WEB server to AS400. The web server has not DB2 library neither ODBC library.
I have installed XAMPP in my Windows computer, and one of my colleagues also did.
He has Client Access on his Computer.
We both installed:
- XAMPP
- ibm_data_server_driver_package_win32_v10.5.exe
We tried to install PECL DB2 extension (LINK) but unsuccessfully (got error ".\php.exe appears to have a suffix .exe, but config variable php": seems that nobody has solved this problem on Windows...).
Then we saw that XAMPP has the ODBC Module already on it, so we tried to estabilish a connection with obdc_connect. Referring to THIS question we are now able to connect to AS400 using his computer with Client Access Drivers using:
$user = 'USER';
$password = 'PASS';
$hostname = '192.168.1.30';
$server="Driver={Client Access ODBC Driver (32-bit)};
System=$hostname;
Uid=$user;
Pwd=$password;";
odbc_connect($server, $user, $password);
With my computer I tried to use the IBM data server driver already installed using:
$user = 'USER';
$password = 'PASS';
$hostname = '192.168.1.30';
$server="Driver={IBM DB2 ODBC DRIVER};
System=$hostname;
Uid=$user;
Pwd=$password;";
odbc_connect($server, $user, $password);
and I get always this error:
Warning: odbc_connect(): in C:\xampp\htdocs\test.php on line 11
When I've tried with IBM DB2 ODBC DRIVER on my colleague's computer, I've also got the same error.
What is this error? No information is specified.
We would like to use db2_connect instead of odbc_connect. What should we do to install this extension? I asked my ISP to install the db2 extension on the WEB server but I'm still waiting... maybe he also encountered some problems (the WEB server is a UNIX machine).
Any help is much apprecciated!

Categories