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.
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 have a problem to connect my online MySQL database from my local system.
I installed XAMPP on my Windows 7 and created a PHP file with this code:
<?php
$db_path = mysqli_connect('printcity24.com', 'printci1_admin', 'xr10s20191', 'printci1_db', '3306');
if(!$db_path) {
echo mysqli_connect_error();
}else{
echo "Connected successfully";
}
?>
Then i created a database on my website : www.printcity24.com
My web host admin configured my host and opened firewall.
When i use XAMPP command line to connect to my database every thing is ok, i can connect to my database remotely with this code :
# mysql -u printci1_admin -p -h printcity24.com
but when i use php code to connect to my database i get this error :
Warning: mysqli_connect(): MySQL server has gone away in D:\Xampp Server\htdocs\st\index.php on line 2
Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in D:\Xampp Server\htdocs\st\index.php on line 2
MySQL server has gone away
I upload my php code on to other websites and test for connection and everything is "ok" but on my local xampp can't connect.
In this link said i have to use this command :
setsebool -P httpd_can_network_connect=1
but I don't know where to put this code and how to configure my xampp.
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.
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 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;