【问题标题】:Cassandra PHP PDO not retrieving all recordsCassandra PHP PDO 未检索所有记录
【发布时间】:2014-02-03 17:38:59
【问题描述】:

我正在尝试将 Cassandra 2.0 与 PHP 和 PDO 扩展一起使用。 它似乎可以正常工作,但是我在检索记录时遇到了问题。

我的代码如下

// Connect to two hosts
 $dsn = "cassandra:host=localhost;port=9160,host=localhost,port=9160";
 $db = new PDO($dsn);
// Select Keyspace
 $db->exec("USE mykeyspace");
// Create and Excecute query
 $stmt = $db->prepare("SELECT * FROM users");
 $result = $stmt->execute();
// Dump to data
 var_dump($stmt->fetchAll());

这是我的 var_dump 的结果

array(3) { [0]=> array(6) { ["user_id"]=> int(1745) [0]=> int(1745) [""]=> string(5) "smith " [1]=> string(0) "" [2]=> string(4) "john" [3]=> string(5) "smith" } [1]=> array(6) { ["user_id "]=> int(1744) [0]=> int(1744) [""]=> string(3) "doe" [1]=> string(0) "" [2]=> string(4) "john" [3]=> 字符串(3) "doe" } [2]=> 数组(6) { ["user_id"]=> int(1746) [0]=> int(1746) [""] => string(5) "smith" [1]=> string(0) "" [2]=> string(4) "john" [3]=> string(5) "smith" } }

数据在那里,但根本没有组织。为什么没有 fname 是我的列的名称之一。数据在那里,但其中一些只是另一个数字数组键。

表结构为Cassandra示例(入门)数据如下

 user_id | fname | lname
---------+-------+-------
    1745 |  john | smith
    1744 |  john |   doe
    1746 |  john | smith

我做错了吗?

谢谢

【问题讨论】:

  • 你能告诉我们users表的表结构吗?
  • 我已编辑问题
  • 你可以试试$stmt->fetchAll(PDO::FETCH_ASSOC); 并发布你得到的数组吗?
  • array(3) { [0]=> array(2) { ["user_id"]=> int(1745) [""]=> string(5) "smith" } [1 ]=> array(2) { ["user_id"]=> int(1744) [""]=> string(3) "doe" } [2]=> array(2) { ["user_id"]=> int(1746) [""]=> 字符串(5) "史密斯" } }

标签: php pdo cassandra


【解决方案1】:

尝试更改您的驱动程序,这个 cassandra pdo 非常旧,我使用 dataStax 并且工作得很好

【讨论】:

    猜你喜欢
    • 2016-09-10
    • 1970-01-01
    • 2014-09-09
    • 1970-01-01
    • 2018-10-02
    • 1970-01-01
    • 2014-03-11
    • 1970-01-01
    • 2013-05-23
    相关资源
    最近更新 更多