【问题标题】:Cassandra remote database not retriving data with PHP while retriving with nodejsCassandra远程数据库在使用nodejs检索时未使用PHP检索数据
【发布时间】:2015-03-29 19:17:20
【问题描述】:

我在使用 PHP 访问 cassandra 数据库中的数据时遇到问题,而我可以使用 nodejs 访问。

这是我的 PHP 代码

$s = "SELECT * FROM user_project_0001 WHERE usermail='sohini.neogi#ATwitslog.com'";
        $stmt = $this->dbf->prepare( $s );
        if( !$stmt ) {
            echo "<br/>\nPDO::errorInfo():<br/>\n";
            print_r($this->dbf->errorInfo());
            echo '<br/>';
        }
        $stmt->execute();
        echo $stmt->rowCount();
        /** Plusieurs projets pour cet utilisateur **/
        if( $stmt->rowCount() > 1 ) {
            echo '<select name="project_name" id="project_name_select">';
            echo '<option value="">' . __( 'Please select', 'weenat-plugin' ) . '</option>';
            while ($row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
                echo '<option value="' . $row['project_name'] . '" ';
                if( isset( $_POST['project_name'] ) && $row['project_name'] == $_POST['project_name'] )
                    echo 'selected="selected"';
                echo '>' . $row['project_name'] . '</option>';
            }
}

我得到 0 条记录,而如果我尝试使用 nodejs 访问相同的查询,我得到 3 条记录。

这里是nodejs代码

client.execute("SELECT * FROM user_project_0001 WHERE usermail='sohini.neogi#ATwitslog.com'", function (err, result) {
           if (!err){

               if ( result.rows.length > 0 ) {
                   console.log("Total Records = %d", result.rows.length);
                   var user = result.rows[0];
                   console.log("name = %s", user.usermail);
                   console.log("pname = %s", user.project_name);
               } else {
                   console.log("No results");
               }
           }


       });

对于 PHP,我使用 PDO 连接

$dsn = 'cassandra:host=xx.xxx.xx.xx;port=9160';
$this->dbf = new PDO($dsn);
 $this->dbf->exec("USE senskey01");

对于 nodejs,这是我与 cassandra 驱动程序的连接

var client = new cassandra.Client({contactPoints: ['xx.xxx.xx.xx'], keyspace: 'senskey01'});

我不明白为什么 PHP 无法访问数据库。

【问题讨论】:

  • 你在哪里设置 php 中的键空间?

标签: php database node.js cassandra


【解决方案1】:

我不是 PHP 人,但通过查看 PDO 的实例化以及查询,我认为它缺少键空间。尝试将您的代码修改为:

  1. 要么连接到特定的键空间
  2. 或完全限定查询中的表名:

    $s = "SELECT * FROM senskey01.user_project_0001 WHERE usermail='sohini.neogi#ATwitslog.com'";
    

【讨论】:

  • 不,它不起作用。另外让我告诉你,我已经使用过这样的键空间 $this->dbf->exec("USE senskey01");
猜你喜欢
  • 1970-01-01
  • 2013-06-21
  • 2011-06-30
  • 1970-01-01
  • 1970-01-01
  • 2011-10-14
  • 2017-05-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多