{"id":32765266,"url":"https://github.com/uri2x/php-cql","last_synced_at":"2025-11-04T06:02:14.116Z","repository":{"id":16436151,"uuid":"19187698","full_name":"uri2x/php-cql","owner":"uri2x","description":"Native Apache Cassandra and ScyllaDB connector for PHP based on the CQL binary protocol (v3), without the need for an external extension.","archived":false,"fork":false,"pushed_at":"2024-06-28T13:47:43.000Z","size":63,"stargazers_count":19,"open_issues_count":3,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-08-21T01:36:24.581Z","etag":null,"topics":["cassandra","composer-package","php","scylladb"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uri2x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-26T20:26:48.000Z","updated_at":"2025-05-24T20:39:29.000Z","dependencies_parsed_at":"2023-02-16T16:32:35.266Z","dependency_job_id":null,"html_url":"https://github.com/uri2x/php-cql","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/uri2x/php-cql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri2x%2Fphp-cql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri2x%2Fphp-cql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri2x%2Fphp-cql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri2x%2Fphp-cql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uri2x","download_url":"https://codeload.github.com/uri2x/php-cql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uri2x%2Fphp-cql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282585676,"owners_count":26693761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-04T02:00:05.887Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra","composer-package","php","scylladb"],"created_at":"2025-11-04T06:01:16.616Z","updated_at":"2025-11-04T06:02:14.105Z","avatar_url":"https://github.com/uri2x.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# uri2x/php-cql\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nLast update : 2023/07/08\n\nNative [Apache Cassandra](https://cassandra.apache.org) and [ScyllaDB](https://www.scylladb.com) connector for PHP based on the CQL binary protocol (v3),\nwithout the need for an external extension.\n\nRequires [PHP](https://www.php.net/) version \u003e5, Cassandra \u003e1.2, and any ScyllaDB version.\n\nInstallation\n------------\n\nEither:\n\n* Via [Composer](https://getcomposer.org/):\n```bash\n$ composer require uri2x/php-cql\n```\nOR\n\n* Copy `Cassandra.php` to your project and include it.\n\nImportant\n---------\n\nMake sure you turn on the native transport for Cassandra by editing your\ncassandra.yaml file and adding the following line:\n\n    start_native_transport: true\n\nUsage\n-----\n\n#### Available methods\n\nconnect($host, $user = '', $passwd = '', $dbname = '', $port = 9042)\n\n    Connects to a Cassandra node.\n\n    @param string $host   Host name/IP to connect to use 'p:' as prefix for persistent connections.\n    @param string $user   Username in case authentication is needed.\n    @param string $passwd Password in case authentication is needed.\n    @param string $dbname Keyspace to use upon connection.\n    @param int    $port   Port to connect to.\n    @param int    $retries: Number of connection retries (default: 3, useful for persistent connections in case of timeouts).\n\n    @return int The socket descriptor used. FALSE if unable to connect.\n\nclose()\n\n    Closes an opened connection.\n\n    @return int 1\n\nquery($cql, $consistency = CASSANDRA_CONSISTENCY_ALL, $values = [])\n\n    Queries the database using the given CQL.\n\n    @param string $cql         The query to run.\n    @param int    $consistency Consistency level for the operation.\n    @param array  $values      Values to bind in a sequential or key=\u003evalue format,\n                               where key is the column's name.\n\n    @return array Result of the query. Might be an array of rows (for SELECT),\n                  or the operation's result (for USE, CREATE, ALTER, UPDATE).\n                  NULL on error.\n\nbind_param($value, $column_type)\n     Returns a binded parameter to be used with the query method (static method)\n\n     @param mixed $value Value to bind        The query to run.\n     @param int   $type  Value type out of one of the Cassandra::COLUMNTYPE_* constants\n\n     @return array value to be used as part of the $values parameter of the query method\n\nprepare($cql)\n\n    Prepares a query.\n\n    @param string $cql The query to prepare.\n\n    @return array The statement's information to be used with the execute\n                  method. NULL on error.\n\n\nexecute($stmt, $values, $consistency = CASSANDRA_CONSISTENCY_ALL)\n\n    Executes a prepared statement.\n\n    @param array $stmt        The prepared statement as returned from the\n                              prepare method.\n    @param array $values      Values to bind in key=\u003evalue format where key is\n                              the column's name.\n    @param int   $consistency Consistency level for the operation.\n\n    @return array Result of the execution. Might be an array of rows (for\n                  SELECT), or the operation's result (for USE, CREATE, ALTER,\n                  UPDATE).\n                  NULL on error.\n#### Procedural\nIn addition, a wrapper has been made for those who prefer to work with\nprocedural programming. To use the wrapper, make sure to include\n`Cassandra_Procedural.php` that contains the following methods:\n\ncassandra_connect($host, $user = '', $passwd = '', $dbname = '', $port = 9042)\n\n    Same as $Cassandra-\u003econnect() above. Returns an object type if connection\n    was successfull. Otherwise returns NULL.\n\ncassandra_close($obj)\n\n    Same as $Cassandra-\u003eclose() above. Use $obj from cassandra_connect as the\n    first parameter.\n\ncassandra_query($obj, $cql, $consistency = CASSANDRA_CONSISTENCY_ALL, $values = [])\n\n    Same as $Cassandra-\u003equery() above. Use $obj from cassandra_connect as the\n    first parameter.\n\n cassandra_bind_param($value, $column_type)\n\n    Same as $Cassandra-\u003ebind_param() above\n\ncassandra_prepare($obj, $cql)\n\n    Same as $Cassandra-\u003eprepare() above. Use $obj from cassandra_connect as the\n    first parameter.\n\ncassandra_execute($obj, $stmt, $values, $consistency = CASSANDRA_CONSISTENCY_ALL)\n\n    Same as $Cassandra-\u003eexecute() above. Use $obj from cassandra_connect as the\n    first parameter.\n\n\nSample usage\n------------\n```php\n\n\u003c?php\n\nrequire_once('vendor/autoload.php');\n\nuse CassandraNative\\Cassandra;\n\n$obj = new Cassandra();\n\n// Connects to the node:\n$res = $obj-\u003econnect('127.0.0.1', 'my_user', 'my_pass', 'my_keyspace');\n\n// Tests if the connection was successful:\nif ($res)\n{\n    // Queries a table:\n    $arr = $obj-\u003equery('SELECT col1, col2, col3 FROM my_table WHERE id=?',\n      Cassandra::CONSISTENCY_ONE,\n      [Cassandra::bind_param(1001, Cassandra::COLUMNTYPE_BIGINT]);\n\n    // $arr, for example, may contain:\n    // Array\n    // (\n    //     [0] =\u003e Array\n    //         (\n    //             [col1] =\u003e first row\n    //             [col2] =\u003e 1\n    //             [col3] =\u003e 0x111111\n    //         )\n    //\n    //     [1] =\u003e Array\n    //         (\n    //             [col1] =\u003e second row\n    //             [col2] =\u003e 2\n    //             [col3] =\u003e 0x222222\n    //         )\n    //\n    // )\n\n    // Prepares a statement:\n    $stmt = $obj-\u003eprepare('UPDATE my_table SET col2=?,col3=? WHERE col1=?');\n\n    // Executes a prepared statement:\n    $values = ['col2' =\u003e 5, 'col3' =\u003e '0x55', 'col1' =\u003e 'five'];\n    $pResult = $obj-\u003eexecute($stmt, $values);\n\n    // Upon success, $pResult would be:\n    // Array\n    // (\n    //     [0] =\u003e Array\n    //         (\n    //             [result] =\u003e success\n    //         )\n    //\n    // )\n\n    // Closes the connection:\n    $obj-\u003eclose();\n}\n```\nor, same as above in procedural style:\n```php\n// Connects to the node:\n$handle = cassandra_connect('127.0.0.1', 'my_user', 'my_pass', 'my_keyspace');\n\n// Tests if the connection was successful:\nif ($handle)\n{\n    // Queries a table:\n    $arr = cassandra_query($handle, 'SELECT col1, col2, col3 FROM my_table');\n\n    // Prepares a statement:\n    $stmt = cassandra_prepare($handle,\n        'UPDATE my_table SET col2=?,col3=? WHERE col1=?');\n\n    // Executes a prepared statement:\n    $values = ['col2' =\u003e 5, 'col3' =\u003e '0x55', 'col1' =\u003e 'five'];\n    $pResult = cassandra_execute($handle, $stmt, $values);\n\n    // Closes the connection:\n    cassandra_close($handle);\n}\n```\n\nExternal links\n--------------\n\n1. Datastax's blog introducing the binary protocol:\nhttp://www.datastax.com/dev/blog/binary-protocol\n\n2. CQL definitions\nhttps://cassandra.apache.org/_/native_protocol.html\n\n\nLicense\n-------\n\n    The MIT License (MIT)\n\n    Copyright (c) 2023 Uri Hartmann\n\n    Permission is hereby granted, free of charge, to any person obtaining a\n    copy of this software and associated documentation files (the \"Software\"),\n    to deal in the Software without restriction, including without limitation\n    the rights to use, copy, modify, merge, publish, distribute, sublicense,\n    and/or sell copies of the Software, and to permit persons to whom the\n    Software is furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in\n    all copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n    DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furi2x%2Fphp-cql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Furi2x%2Fphp-cql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Furi2x%2Fphp-cql/lists"}