Using Cassandra PDO Driver on Windows - php

Is there any way to have Cassandra PDO at Windows with Wamp?
This is for development purposes I don't want to install Linux and change all the environment.
https://code.google.com/a/apache-extras.org/p/cassandra-pdo/
I'm using Windows 7 (64 Bit), Wamp 2.5, PHP 5.5.

OK, here's what I found out:
1) It's totally possible
2) The docs that appear in the first google search results are a bit obsolete
Start by downloading the latest Datastax Community Cassandra here:
http://planetcassandra.org/cassandra/
Install & setup properly. In fact, most of the configuration is done by the installer, you just have to edit the apache-cassandra/conf/cassandra.yaml file to find all paths to /var/lib... and change those into something like d:/cassandra/... That includes "commitlog", "data", "saved_caches". Restart the Cassandra service, examine the logs. Mine shown no problem. The OpsCenter at ...:8888/opscenter/index.html was working fine, showing one node online.
Now, the PHP part.
There's a sneaky thing called Thrift. From what I've learned today (I first heard about Cassandra and Thrift yesterday), it's a way describe a binary protocol of connecting to some online service, in this case, to Cassandra. It will basically generate PHP files that will provide all the connectivity you need from PHP itself (no extensions needed).
You will need:
1) The Thrift PHP libs
2) The .exe Thrift compiler
Both can be downloaded here:
https://thrift.apache.org/download
Then use the following command to compile PHP files that will act as a "driver" to connect your PHP applications to Cassandra:
thrift --gen php D:\DataStaxCommunity\apache-cassandra\interface\cassandra.thrift
Put the result in some PHP include_path folder.
Also, find the PHP Thrift libs (in the libs archive from the same download page) and put those in a folder accessible to your script (e.g. include_path or the project folder).
Refer this page:
thrift.apache.org/lib/php
I guess that should help!

I have same problem as you, but when i tried this method, it works correctly for me.
Reference link
Here is a code example, very easy to understand :
<?php
require_once 'Cassandra/Cassandra.php';
$o_cassandra = new Cassandra();
$s_server_host = '127.0.0.1'; // Localhost
$i_server_port = 9042;
$s_server_username = ''; // We don't use username
$s_server_password = ''; // We don't use password
$s_server_keyspace = 'cassandra_tests';
$o_cassandra->connect($s_server_host, $s_server_username, $s_server_password, $s_server_keyspace, $i_server_port);
$s_cql = "CREATE TABLE carles_test_table (s_thekey text, s_column1 text, s_column2 text,PRIMARY KEY (s_thekey));";
$st_results = $o_cassandra->query($s_cql);

Related

locating dependencies on windows php extension builds

I am writing a php extension for a library. I have a generic swig file to build wrappers for the library. This has been very successful so far on Python.
A user is trying to build the library for php and I am trying to help out. I generated the code using swig, and I can build the .dll extension using Visual Studio. The problem is getting it into php. When I build php_mylib.dll, it needs to find mylib.dll and it can't.
So I am trying to build via the command line a la:
http://blog.benoitblanchon.fr/build-php-extension-on-windows/
I have put all the files to be compiled and the libraries needed (i.e. mylib64.lib and mylib64.dll) in a folder called mylib in the C:\php-src\ext folder with all the other extension folders.
The problem is I that I can't get the config.w32 file to communicate the location of mylib. Here is my config.w32 file (pretty standard -- you can see that I copied it from the curl config.w32 file):
// $Id$
// vim:ft=javascript
ARG_ENABLE("mylib", "mylib support", "no");
if (PHP_MYLIB != "no") {
if (CHECK_LIB("mylib64.lib", "mylib", PHP_MYLIB) &&
CHECK_HEADER_ADD_INCLUDE("mylib_cpp.h", "CFLAGS_MYLIB")
) {
EXTENSION("mylib", "mylib_c_wrap.cpp", true);
AC_DEFINE('HAVE_MYLIB', 1, 'Have mylib library');
// TODO: check for curl_version_info
} else {
WARNING("mylib not enabled; libraries and headers not found");
}
}
When I run buildconf and then configure --disable-all --enable-cli --enable-mylib it always shoots me the 'libraries and headers not found' warning from the script.
On Unix systems (config.m4) there appears to be a PHP_ADD_LIBRARY_WITH_PATH macro but I don't see any equivalent for windows. It seems like this is what I need.
I have also tried adding the full path to mylib into the system's path but to no avail. It seems like there might be an environment variable somewhere in the PHP build cosmos that needs to be set to find external dependencies, but I can't find any information about this.
It would also be good to do all this as a Visual Studio project -- easier for Windows users the world over. I have not seen anything on the web that looks like this.
By the way, I have successfully phpized this library using the same swig+phpize procedure on Linux (I followed this guide for the php part:http://www.sitepoint.com/install-php-extensions-source/) and it works beautifully.
In most cases you can use this info to build a PECL extension https://wiki.php.net/internals/windows/stepbystepbuild#building_pecl_extensions . Your config.w32 looks ok, though please note that that when depending on some additional library, usually it should be ARG_WITH(...) for semantics. Your lib stuff can be then put into the deps dir as in the wiki.
Another way could be passing --with-extra-libs and --with-extra-includes to configure. Those have to contain paths to *.lib and *.h dirs respectively. When using a static lib, that should be it, otherwise you'll need to place the corresponding *.dll onto the %path% for the ext to work.
Hope this helps, otherwise you can also gain some attention on the PHP mailing lists or specifically on #winphp-dev at freenode.
Thanks.

Thrift + Cassandra + PHP + Windows?

Connecting to Cassandra with PHP is really a pain. The documentations at Apache and DataStax are extremely poorly written - for Windows users.
I have Thrift installed (I believe!) via Chocolatey. But I am still not able to compile php code for Cassandra using thrift.
If you look at this link ,
now we can compile php code for Cassandra using thrift I used command: d:\cassandra\trift\thrift.exe --gen php
d:\cassandra\interface\cassandra.thrift
So what is cassandra.thrift and where does it come from?? WHAT should I put inside it??
If I follow the instruction exactly, I get this error,
Could not open input file: d:\cassandra\interface\cassandra.thrift
So what is going on?
How do I make this work?
I have tried to install DataStax PHP Driver for Apache Cassandra and that documentation even worst.
Why PHP modules do not come with Cassandra like it does for MongoDB? Most of the independent drivers I found are outdated, not supported anymore or abandoned.
EDIT:
From the README,
Install the PHP extension
Installing with pecl
The PHP driver is not published to the official PECL repository yes.
You can still install it using pecl by specifying the provided
package.xml file path as the argument to pecl install command.
Install the 2.0 version of the C/C++ driver
not published to the official PECL repository yes - is it yes or yet?
Obtaining Build Dependencies
CMake
Git
ActiveState Perl
Python v2.7.x
I have downloaded and installed. Then, what? In Building the Driver,
A batch script has been created to detect installed versions of Visual...
What? Where does A batch script suddenly come from??
Then,
First you will need to open a “Command Prompt” (or Windows SDK Command
Prompt) to execute the batch script.
Usage: VC_BUILD.BAT [OPTION...]
--DEBUG Enable debug build
--RELEASE Enable release build (default)
--DISABLE-CLEAN Disable clean build
....
What are these bunch of '--' for?
To build 32-bit shared library:
VC_BUILD.BAT --X86 To build 64-bit shared library:
VC_BUILD.BAT --X64
Where does .BAT come from? What should I put inside it? Where should I run it from??
After all, what are those Build Dependencies for? How do I use them??
Just hope that someone can write a proper guide then the guide above - it is frightening! (if you compare the guides in MongoDB, it is far better and professional)
EDIT 2:
First error when I run the .bat from my desktop,
I have git installed already but I still have this error,
After fixing git issue above, I have a new one - it just frozen there, nothing happens,
The IDL file cassandra.thrift is usually part of the cassandra package, but you can find it following the link above. The link points to trunk, you may want another version.
After you downloaded the right version of that file or better found it in your downloaded Cassandra package in the interface folder, generate the code as outlined in the documentation you have. The rest should be easy.
Why PHP modules do not come with Cassandra like it does for MongoDB? Most of the independent drivers I found are outdated, not supported anymore or abandoned.
I'm not really sure about that, but my guess is that the fact CQL is promoted heavily for a while now instead of using the raw Thrift API - the latter is a complex task, while CQL is more easy to use - is one of the key factors why it is this way. It more or less eliminates the need for another wrapper.
PS: Just to be sure:
thrift.exe --gen php d:\cassandra\interface\cassandra.thrift
could not open input file cassandra.thrift
Of course you point to the right drives, folders and files, do you?
Forget about Thrift and the 'beta', I found a better solution. It very straight forward and extremely easy!
Example codes,
require_once 'lib/Cassandra/Cassandra.php';
$cassandra = new Cassandra();
$s_server_host = '127.0.0.1'; // Localhost
$i_server_port = 9042;
$s_server_username = 'admin'; // We don't use username
$s_server_password = 'password'; // We don't use password
$s_server_keyspace = 'demo'; // We don't have created it yet
$cassandra->connect($s_server_host, $s_server_username, $s_server_password, $s_server_keyspace, $i_server_port);
// Tests if the connection was successful:
if ($cassandra) {
// Select:
// Queries a table.
$cql = "SELECT * FROM users;";
// Launch the query.
$results = $cassandra->query($cql);
// Update:
// Prepares a statement.
$stmt = $cassandra->prepare('UPDATE users SET first_name = ?, last_name = ? where id = ?');
// Executes a prepared statement.
$values = array('first_name' => 'Fred', 'last_name' => 'Smith', 'id' => '1');
$result = $cassandra->execute($stmt, $values);
// Insert:
// Prepares a statement.
$stmt = $cassandra->prepare('INSERT INTO users (id, first_name, last_name)
VALUES (:id, :first_name, :last_name)');
// Executes a prepared statement.
$values = array('first_name' => 'John', 'last_name' => 'Robinson', 'id' => '4');
$result = $cassandra->execute($stmt, $values);
// Delete:
// Prepares a statement.
$stmt = $cassandra->prepare('DELETE FROM users WHERE id = :id');
// Executes a prepared statement.
$values = array('id' => '4');
$result = $cassandra->execute($stmt, $values);
// Closes the connection.
$cassandra->close();
}
Update:
The datastax PHP driver is now GA and binaries are available for download (no need to build it yourself):
https://github.com/datastax/php-driver
Regarding the DataStax PHP driver, the instructions are being improved per your feedback as I type.
Because this Driver is in Beta, we do not yet have pre compiled binaries that you can simply download. They will be available once the driver is GA. For now you will have to build them yourself.
The process for building the binaries is very straight forward. 1) Install the dependencies 2) run vc_build.bat.
You can find the vc_build.bat here (just right click save as from your browser):
https://raw.githubusercontent.com/datastax/php-driver/master/ext/vc_build.bat

Couchbase PHP Connect Hello World! on Mac

I installed the Couchbase Server and its PHP SDK through brew install libcouchbase on Mac. The server admin console is running/working fine on http://127.0.0.1:8091/. I added a hello.php file with the below code in /Library/WebServer/Documents/hello.php.
<?php
$cb = #new Couchbase("http://127.0.0.1:8091/",'username','password');
if($cb->getResultCode() != COUCHBASE_SUCCESS){
throw Exception('Cannot connect to couchbase!');
} else {
echo "Hello World!";
}
When I go to http://127.0.0.1:8091/hello.php, I get an error saying Not found.. What is the problem?
When I go to http://127.0.0.1:8091/hello.php, I get the below error
Not found.. What is the problem?
You are going to the wrong port. Port 8091 is the Couchbase Server Console interface. It looks like you are trying to deploy your hello.php script using the Apache server shipped with OS X which uses the default http port (80). The script is also located in the wrong folder. I believe /Library/WebServer/Documents/ is for static content only.
Given the problem you have ran into it make me suspect that you are trying to learn too many new things at once. You should try running the script outside of a Apache first and get it working there.
php hello.php
It is also worth pointing out that you are using the older 1.X version of the Couchbase PHP SDK, you will want to use the new 2.X version.
I assume you've anonymized the code above, but be sure in place of where you have 'username' you have the bucket name and similarly for the bucket password or empty string if no password. Also, check the docs as the connect string you're using is not necessarily the preferred..
Note for debugging these kinds of things you can set LCB_LOGLEVEL to a higher level as mentioned in the documentation. The way you set an envvar varies based on how you're deploying PHP, but you can easily just test it at the command line.

Connect PHP with SAP Database

So, I already followed all the steps below for saprfc windows installation.
1) Extract zip file saprfc-$VERSION$-$PHP_VERSION$.zip
2) Copy php-saprfc.dll to your extensions directory (e.g. C:\PHP\extensions)
3) Edit php.ini file (in windows system dircetory, e.g. C:\WINNT, C:\WINDOWS)
and add line: 'extension=php_saprfc.dll'
4) Copy librfc32.dll (from SAPGUI install CD) to the windows system
directory or simple install SAPGUI on your machine.
Another source said we will we need SAP SDK. Is it really needed for Windows?
Also, will it be possible to code PHP connect to SAP in a computer that doesn't have SAP program? Or we only can do those installations in computer that has SAP application?
Then after the installation, what do I have to do next? I am trying to do steps below, yet still confused....
1) Extract php sources to C:\PHP-x.y.z
2) Extract php win support files to C:\PHP-x.y.z\win32
3) Install RFCSDK to C:\PHP-x.y.z\rfcsdk
4) Copy SAPRFC sources to C:\PHP-x.y.z\ext\saprfc
5) Copy php4ts.lib or php5ts.lib (from PHP binaries) to C:\PHP-x.y.z\win32
6) For PHP5 copy saprfc.dsp5 to saprfc.dsp
6) Open project C:\PHP-x.y.z\ext\saprfc\saprfc.dsp in Microsoft Visual C++ 6.0
7) Under Tools|Option|Directory set path for Include files and for Library files
(C:\PHP-x.y.z\win32\include; C:\PHP-x.y.z\rfcsdk\include;
C:\PHP-x.y.z\win32\lib; C:\PHP-x.y.z\rfcsdk\lib)
8) Set active configuration to "saprfc - Windows_TS" (under Build menu)
9) Build php_saprfc.dll.
10) Compiled DLL you find in C:\PHP-x.y.z\Release_TS directory
Where to get PHP sources, PHP win support, and how to compile the program?
Sorry, I am totally new to this. Looking for the answers. Thank you very much!
Building "windows extensions" is explained in general here:
https://wiki.php.net/internals/windows/stepbystepbuild
There is also explained which version of VS you need for which PHP version.
I also tried to build the sapnwrfc extension for PHP 5.5 on windows, but failed at some part...my progress/documentation is here:
https://github.com/piersharding/php-sapnwrfc/issues/6
Maybe you can progress further :-)

How to configure wampserver for spatialite

I am in windows 7. I installed WAMPServer. Now, I can not load spatialite libraries. It is showing warning..
Warning: SQLite3::loadExtension() [sqlite3.loadextension]: Not
supported in multithreaded Web servers
Here is my total configuration procedure, what I have done...
From this link I got spatialite lib. I copied "libspatialite-1.dll" and paste it to "D:\wamp\bin\php\php5.3.8\ext" which contains php extention dlls.
http://www.gaia-gis.it/spatialite-2.3.1/libspatialite-win-x86-2.3.1.zip
Then I edited php.ini file. I changed the following configuration.
.
sqlite3.extension_dir = C:\libspatialite-win-x86-2.3.1\bin
.
extension=libspatialite-1.dll
.
enable_dl = On
And lastly, I copy and paste all the libraries from my downloaded libspatialite-win-x86-2.3.1 to my project folder(libspatialite.a, libspatialite.dll.a, libspatialite.la) in my php code i write the script as follows...
<?php
$db = new SQLite3('sixcommunes.sqlite');
$db->loadExtension('libspatialite.a');
$rs = $db->query('SELECT spatialite_version()');
while($row = $rs->fetchArray()){
print "<h3>SQLite version: $row[0]</h3>";
}
?>
I do not know what I have done wrong or how to solve this problem?
Haven't seen any answer, so giving my own. I have used spatialite in C#, I think for using Spatialite Extensions you don't have to load libspatialite like a usual PHP extension, instead something similar to this should be done. (this is c# code, just trying to give you an idea)
SQLiteCommand sqliteCommand = new SQLiteCommand(String.Format("SELECT
load_extension('{0}');", "libspatialite-2.dll"), connection);
sqliteCommand.ExecuteNonQuery();
You have to execute Select load_extension("libspatialite-2.dll") on sqlite to use Spatialite.
Hope this helps

Categories