Cassandra PDO connection PHP - php

I've got Cassandra working nicely on Debian server however I'm hoping to connect to it from a PHP application.
Currently it seems PDO it the way to go for anything complex as I'm able to use CQL. I'm using the latest forked version of the Apache Cassandra-PDO project.
I'm using the latest Cassandra 2.03 and I can connect to it fine from CQLSH in the terminal.
When I try and connect in PHP using the following code
$db_handle = new PDO("cassandra:host=localhost;port=9160");
I get the following error
Fatal error: Uncaught exception 'PDOException' with message 'CQLSTATE[08006] [8] TTransportException: Transport not open' in /var/www/index.php:9 Stack trace: #0 /var/www/index.php(9): PDO->__construct('cassandra:host=...') #1 {main} thrown in /var/www/index.php on line 9
I've seem a few issues alike on the internet, but no solutions as yet. Hopefully someone can provide some insight into the issue here.

Error 8006 is connection failure. I think you need login and password in PDO Statment like this:
$pdo = new PDO('mysql:host=localhost;dbname=products', 'root', 'root');

Try running 'nodetool status' from the cli to verify the IP address the server is running on.
Then perhaps change localhost to 127.0.0.1 if instead the local host.

Related

server has gone away php mysql connexion error

I have a problem when I try to log to my database with php. I have a website in php and I need to use a database so I have file where I try to connect :
$db = new PDO('mysql:host=IP;dbname=DB_Name', 'Username', '********');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $db;
Then I have an error :
Fatal error: Uncaught PDOException: Packets out of order. Expected 0
received 1. Packet size=78 in /var/www/html/index.php:6 Stack trace:
#0 /var/www/html/index.php(6): PDO->__construct() #1 {main} Next PDOException: SQLSTATE[HY000] [2006] MySQL server has gone away in
/var/www/html/index.php:6 Stack trace: #0 /var/www/html/index.php(6):
PDO->__construct() #1 {main} thrown in /var/www/html/index.php on line
6
My database is on a VPS. The database is installed on it with my php code.
I already looked on internet for solution but nothing changed.
Thanks for your help.
if you’re getting the Packets out of order error in the PHP log, there’s an high chance that the issue is due to the fact that there’s an incompatibility between the PHP and MySQL versions you’re using. If upgrading them is not an option, you could try to add the following statement to the PHP script that causes the issue:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
Maybe this may help...
screenshot of "SHOW VARIABLES LIKE '%timeout%'"

PHP connect to MS Access database - Provider not found

I know there are tons of questions about this on SO. But I've been trying to fix this since a month with no luck.
At work we have this very old website that uses an access database, and I cannot do anything about it.I want to work on some changes on my local PC using wamp server. So I donwloaded the website along with the db. Here is how it's supposed to connect :
$conn = new COM('ADODB.Connection');
$db = realpath("dbalerts.mdb");
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
But it's giving me this error:
Fatal error: Uncaught exception 'com_exception' with message 'Source: ADODB.Connection
Description:Provider cannot be found. It may not be properly installed.'
in C:\wamp\www\testaccess\index.php:5 Stack trace: #0 C:\wamp\www\testaccess\index.php(5): com->Open('Provider=Micros...') #1 {main} thrown in C:\wamp\www\testaccess\index.php on line 5
It's a test folder whith an index.php where only that code is written. In the same folder is dbalerts.mdb
I tried everything I know. I downloaded AccessDatabaseEngine.exe from MS website which is supposed to have the driver. And it installed properly with no errors( had to uninstall office because it was 64bit)
I am on a win8 machine
Any ideas how I can fix this all while still using COM and ADODB? Because I can't go through changing the connections of every .php file in that website (it's old and poorly designed so not adaptable to changes)

Mongo DB showing an error Fatal error: Uncaught exception 'MongoConnectionException' with message 'Operation now in progress'

Mongo DB showing an error Fatal error: Uncaught exception 'MongoConnectionException' with message 'Operation now in progress' in PHP. How to resolve this error and why this error comes.
This typically means the driver has issues connecting to the database. I've learned this through the very first result in Google when pasting your question ;)
As Remon said, "I have an error please help" doesn't work very well when asking programming questions.
Usual things to make sure are, that Mongodb is running and you are connecting to the right host:port e.g.
$m = new Mongo();
If it's not in the localhost (your machine) and default port try this.
$con = new Mongo("mongodb://{$username}:{$password}#{$host}");
Also try to connect to the database using the mongo shell interface.
I had this issue when trying to connect to ObjectRocket. The solution was to add my IP to the ACLs and then I no longer got this error.

MongoCursorException 'couldn't get response header'

I am developing a website using PHP and mongodb. I access the mongodb with PECL-mongo, and have run into an annoyance. Every now and then, I get an error like this (I've anonymized the paths)
Fatal error: Uncaught exception 'MongoCursorException' with message 'couldn't get response header' in
/PATH/index.php:38 Stack trace: #0
/PATH/index.php(38): MongoCursor->rewind() #1
/PATH/template.inc(29): get_sidebar() #2
/PATH/index.php(13):
require_once('PATH/...') #3 {main} thrown in PATH/index.php on line 38
According to the documentation, this means:
The driver could not fetch a reply header from the database, so it
gave up. Check if the database is still up and the network is
connected and try the query again.
But I know that the database is up because I am doing this locally on my own machine over loopback. No connection is made to the outside world.
Simply trying again often works. Is this a possibly a bug in PHP's driver for mongo? Could this be a "miscompile" issue (I compiled from source, but with very benign flags, -march=native -O2)?
Has anyone seen this before?
Searching around, I only see references to some stupid facebook game having the same error.
EDIT: I just downgraded my PECL driver to version 1.1.4 and so far, the problem seems have gone away. So this may simply be a bug in the 1.2.x series. If anyone can shed any light on it, that would be great.
EDIT: I am not doing anything complex here, the code that is having the issue litterally looks like this:
$m = new Mongo();
$collection = $m->my_db->collection;
$results = $collection->find(array("favorite"=>true))->limit(5);
i solved this problem with get new version mogodb.dll
you can see http://www.mongodb.org/display/DOCS/PHP+Language+Center

MongoDB giving weird Connection Error

I'm having a problem with connecting to MongoDB with PHP.
This is my code:
<?php
$server = new Mongo('localhost:27017');
$db = $server->sampleDB;
$coll = $db->sample;
?>
This produces the following error:
Fatal error: Uncaught exception 'MongoConnectionException' with message 'localhost:27017: couldn't get host info for localhost' in /var/www/example/index.php:2 Stack trace: #0 /var/www/example/index.php(2): Mongo->__construct('localhost:27017') #1 {main} thrown in /var/www/wexample/index.php on line 2
Found the problem;
Turns out for some reason Mongo was only listening on 127.0.0.1, not localhost.
So, using $server = new Mongo("mongodb://127.0.0.1:27017");, instead of $server = new Mongo("mongodb://localhost:27017"); fixed the problem :)
Thanks for your help guys,
James
Following the PHP Manual
couldn't get host info for [server]
This indicated that DNS could not
resolve the server address you gave.
This could easily be caused by a typo,
for example, "server" instead of
"$server".
As well, you might want to read the Connecting part of the MongoDB section in PHP doc
EDIT
Have you tried this ?:
$server = new Mongo("mongodb://localhost:27017");

Categories