How to setup MongoDB with wamp server - php

I want to use MONGO db with my wampserver3.0.6_x64_apache2.4.23_mysql5.7.14_php5.6.25-7.0.10. I have successfully installed MSI(mongodb-win32-x86_64-2008plus-ssl-3.4.3-signed) and also DLL file for the PHP setup on my Windows 10 Pro, 64-bit Operating System, x64-based processer. But when i go through the below code
echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";
echo extension_loaded("mysql") ? " mysql loaded\n" : " mysql not loaded\n";
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->mydb;
echo "Database mydb selected";
its says ---not loaded and -- mysql loaded and Fatal error: Class 'MongoClient' not found in C:\wamp64\www\mongotest\conn.php on line 5.
I appreciate any help on this.

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

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

MongoDb With Php Dll Not Working

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

Using PDO to connect to Access database (.accdb)

I am having difficulties with connecting to an Access database (specifically an Access 2013 database with an .accdb extension). Here is the code I'm trying to run:
$dbName = $_SERVER["DOCUMENT_ROOT"] . "/test/testdb.accdb";
echo $dbName."<br />";
if (!file_exists($dbName)) {
die("Could not find database file.<br />".$dbName);
}
try {
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};;Dbq=$dbName");
} catch(PDOException $e) {
echo "Error: ".$e->getMessage()."<br />";
}
I have made sure that the testdb file exists in the correct folder, but when I try to create the new PDO, I am getting the following error: "could not find driver".
Now, I have gone back to my ini settings and confirmed that I have the following extensions selected:
php_curl
php_gd2
php_mbstring
php_mssql
php_mysql
php_mysqli
php_pdo_mssql
php_pdo_mysql
php_pdo_sqlite
I am using WAMP version 2.4 with PHP 5.4.16 on a Windows 7 machine. I would appreciate any and all help I can get.
You'll have to install (if your distro has one) or compile the pdo-odbc generic driver: http://php.net/manual/en/ref.pdo-odbc.php

Categories