0- i used above exmple for php file and it work but in yii2 i tried for run that code but i failed.
confiq path:application/backend/common/main-local.php
<?php
return [
'components' => [
'cassandra' => [
'class' => '\beliy\cassandra\Connection',
'keyspace' => 'new',
//'keyspace' => 'myDB',
'servers' => ['127.0.0.1'],
],
'cache' => [
'class' => '\beliy\cassandra\Cache',
'tableName' => 'cache', // dedault 'cache'
'tablePrefix' => 'mega', // default ''
],
],
];
in controller i used the same code in yii2 project
<?php
namespace backend\controllers;
use Yii;
use yii\data\ArrayDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\Json;
require_once Yii::$app->basePath . '/library/PhCass_2-1/php-cassandra.php';
/**
* ProfileController implements the CRUD actions for Profile model.
*/
class NewController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
public function actionIndex()
{
return $this->redirect(['new/home']);
}
public function actionCreate()
{
$nodes = [
'127.0.0.1', // simple way, hostname only
];
// Create a connection.
$connection = new Cassandra\Connection($nodes, 'new');
//Connect
try
{
$connection->connect();
}
catch (Cassandra\Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
exit;//if connect failed it may be good idea not to continue
}
// Set consistency level for farther requests (default is CONSISTENCY_ONE)
//$connection->setConsistency(Request::CONSISTENCY_QUORUM);
// Run query synchronously.
try
{
$q = $connection->querySync('SELECT * FROM country_by_id');
// $response = $q->getResponse();
$rows1 = $q->fetchAll();
foreach($rows1 as $value )
{
var_dump($value['country_name']);
}
}
catch ( Cassandra\Exception $e )
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
// return $this->render( 'create' , [ 'Country' => $Country ] );
}
}
second question:
1- I installed all datastax php-cassandra driver and c extension and i used it , my first question in this topic refered to this issue , my problem is it work in cmd and with netbeans but it does not show any data in my chrome or firefox.
2- i want to learn cassandra and use it in php but i could not. I know cassandra modeling and concept of that but the problem is something i said.
3- i want to use latest version of cassandra driver and newst code to connect to cassandra and use it in yii2.
4- if you know it pls help me.
how to use this site -> https://datastax.github.io/php-driver/features/datatypes/
to learn cassandra php and cassandra in yii2