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.
Related
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 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
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.
I'm having wamp on my windows machine with php 5.5.12 and I have installed mongodb 3.2.0 (64 bit) and added php 1.5.7 dll in wampp extension and completed all the necessary things which required to connect with the mongodb.
Here is my code for connecting the mongoDb.
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->portal;
echo "Database mydb selected";
?>
error message while connecting to db
6.8 Mongo and instantiating the class as follows
php info mongo db
/*Hello I'm Using 1.6.8 Mongo and instantiating the class as follows*/
$mongo = new MongoClient();
$db = $mongo->gwb;
$collection = $db->users;
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.