Class 'MongoClient' not found in xampp - php

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

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 ...

How to connect sql server with php using xampp?

I am trying to connect my SQL server with PHP using Xampp. I have already uploaded dll files in the ext folder but I am unable to connect it.
My PHP version is 7.2.6.
Uploaded dll files are - php_pdo_sqlsrv_72_ts.dll, php_sqlsrv_72_ts.dll.
I have written this code to connect my SQL database with PHP-
<?php
$serverName = "INDO-SERV\SQLEXPRESS,1443";
$uid = "sa";
$pwd = "XXXXXX";
$databaseName = "web";
$connectionInfo = array("UID" => $uid, "PWD" => $pwd, "Database"=>$databaseName);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close( $conn);
?>
I am getting this error when I had tried this-
Fatal error: Uncaught Error: Call to undefined function
sqlsrv_connect() in C:\xampp\htdocs\biometric\db.php:7 Stack trace: #0
{main} thrown in C:\xampp\htdocs\biometric\db.php on line 7.
Anyone has an idea where I am doing wrong or how to connect with the database.
Installation of PHP Driver for SQL Server (sqlsrv and/or pdo_sqlsrv PHP extensions) can be done following the next steps:
Based on Microsoft PHP Drivers for SQL Server Support Matrix download appropriate version of this driver. In your case - version 5.2 or 5.3 (32-bit or 64-bit also depends on PHP version).
Download and install an appropriate ODBC driver - see System Requirements for the Microsoft Drivers for PHP for SQL Server
Load PHP Driver for SQL Server as PHP extension.
Restart Apache
Check the configuration with <?php phpinfo();?>. There should be a section with name pdo_sqlsrv (if you use PDO) and/or sqlsrv (without PDO).
my XAMPP version is 7.0.13
1- Download and Install "SQLSRV40.EXE" on this path:
D:\xampp\php\ext
2- Download and Install "msodbcsql.msi"
3- Edit file ":\xampp\php\php.ini" and add this extensions :
extension=php_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php7ts.dll
4- restart xampp
Note: "SQLSRV40.EXE" Contain this extensions:
php_sqlsrv_7_ts_x86.dll , php_pdo_sqlsrv_7_ts_x86.dll , php7ts.dll
Download driver from:
https://download.microsoft.com/download/f/4/d/f4d95d48-74ae-4d72-a602-02145a5f29c8/SQLSRV510.ZIP
Unzip the files
Copy the dll files in C:\xampp\php\ext\
Open with your favourite editor the file php.ini located in C:\xampp\php\
Insert the extensions:
extension=pdo_sqlsrv_74_ts_x64
extension=sqlsrv_74_ts_x64
Restart Apache and PHP
For the new comers;
You can setup driver and integrate it as in this video explains so in a nutshell;
You should find drivers for php - sql server integration depending to your environment (versions) at links and download the driver that suits for your environment.
You should move the driver file (.dll for windows case) to php/ext folder.
You need to change php.ini as entering a new extension (for example extension=php_sqlsrv_7_ts.dll) by giving your exact file name you have moved to php/ext.
Restart your local server and you should see this extension in phpinfo(), if you can see it's there, you can connect to your db with your credentials and it's done.
Credits goes to creator of the video (applause) :)

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

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.

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.

Mongodb installation

Mongodb installed in linux CentOS server (ssh) with steps mentioned in this url
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/
Started MongoDB server using the command and the status is ok.
sudo service mongod start
When connecting mongodb with PHP (Yii app), it shows error like this.
include(MongoClient.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
PHP code
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->health;
echo "Database mydb selected";
$collection = $db->medical;
echo "Collection selected succsessfully";
?>
Yii2 provide class yii\mongodb\Connection for mongodb connection.
Check below link.
http://www.yiiframework.com/doc-2.0/yii-mongodb-connection.html
MongoDb Extension for Yii 2
http://www.yiiframework.com/doc-2.0/ext-mongodb-index.html
It will resolve your issue.

Categories