Start with Couchbase N1QL query in xampp - php

I was trying to query data from Couchbase server using PHP and N1QL. Please see the code below.
<?php
$cluster = new CouchbaseCluster('127.0.0.1:8091');
$bucket = $cluster->openBucket('travel-sample');
$q = CouchbaseN1qlQuery::fromString("SELECT * FROM `travel-sample`")->consistency(CouchbaseN1qlQuery::REQUEST_PLUS);
$res = $bucket->query($q);
var_dump($res);
?>
Unfortunately, this return NULL. I am usinf Couchbase server 3.0 and PHP SDK. Cam someone help me to correct my N1QL query ?
Regards,
Tismon Varghese

First of all, i was using Couchbase 3.0, so i'm suppose to use N1QL DP3. So i downloaded DP3 from the below URL
https://s3.amazonaws.com/query-dp3/couchbase-query_dev_preview3_x86_win.zip
Extract it, put it on the directory where Couchbase installed (This is not necessary i guess). Extracted directory contains two directories; data and static in addition to a start_turotial.bat and some other files.
Since the .bat file is connected to data directory, we have to change this to get data from Couchbase server. For that, do the following.
Take a backup of the .bat file; right click on it and select 'edit'
change the line cbq-engine -couchbase dir:data to cbq-engine -couchbase http://127.0.0.1:8091/ and save it
Double click on the bat file so that a console window will be popped up (This should be open as long as the query runs). I addition to this, a webpage also opens automatically in your browser; if not, follow the instruction on the popped console window.
..and you are good to go!!!
Regards,
Tismon Varghese.

Related

How do I use a MicroTik API to do a /tool fetch command?

Having an issue trying to use a MicroTik API to issue a /tool fetch command and download a file to a router. I am using a ccr1016 on 6.47.9.
My php script calls this API:
require('lib/routeros.class.php');
The code I am using currently is this:
$fileUrl = "http://".$localIP."/".$remoteSysModel."/".$fileName;
$remoteAPI->write('/tool fetch', false);
$remoteAPI->write('=url='.$fileUrl.'');
Also tried:
$remoteAPI->write('/tool fetch url='.$fileUrl.'');
Both of the above are unsuccessful nothing downloads. Any advice much appreciated.
The API is definitely connecting correctly because i retrieve info from the router using this commend $remoteAPI->comm('/system/routerboard/print'); earlier in the script.
The $fileUrl variable is correct as well and contains this string http://172.27.55.120/rb2011/routeros-verv-6.47.9.npk
Also if i run the command /tool fetch url=http://172.27.55.120/rb2011/routeros-verv-6.47.9.npk in the router cli through winbox, it works correctly and the file downloads.
Any help would be greatly appreciated.
Thanks in advance

Send data from VBA (excel) to php and vice versa

Basically I want to communicate with a MYSQL server using php as the middle-ware.
I cannot connect directly to the database due to drivers needing to be installed and our IT will not allow drivers to be installed on our company computers.
I understand how to insert data using vba ->php->mysql but I cannot figure out how to get data from mysql to excel. vba->php->mysql->php->vba.
I want to do a query and send the results to vba excel.
Here is the VBA Code that works but it also sends multiple spaces back as well. Im not sure if this is the correct way to do this.
Private Sub ExtractPHP()
Dim item As String
Dim objHTTP As Object
Dim URL As String
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://localhost/php/requestdata.php"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencode"
objHTTP.send ("")
Worksheets("hiddendata").Range("k4").Value = Replace(objHTTP.responseText, " ", "")
End Sub
The PHP code is as follows.
<?php
$con = mysqli_connect("localhost","root","","php") or die("Connection was not created!");
$select = "select name FROM users where id=5";
$run = mysqli_query($con,$select);
$value = mysqli_fetch_array($run);
$result = $value["name"];
echo $result;
?>
Result that is placed in the excel file has multiple spaces below the text. Is this the correct way to communicate between excel and mysql?
I am not sure about the VBA method and what exactly you need to do but one solution would be to write requestdata.php to parse the result of your query into a .csv file and then load that into Excel via VBA. Parsing the result array into the .csv plain text format is made even more trivial by the fact that PHP already has a function fputcsv($file, $records) to use (documentation).
i can help you 10% cause i programming in several languages but nothing vba/excell .I programming in php too...anyway my answer for you is :
Let say you create in C: a new folder and you create a runme.bat file there.
Using one methods to run a external .bat file and to grab external result from that runme.bat more or less like in
Execute a command in command prompt using excel VBA
Wait for shell command to complete
you can use like me a method to run from that batch php cli:
you can drop runme.php in that folder as well:
<?php
if(isset($argv[1])){
echo($argv[1]);
//here you can drop some mysql
}
?>
then you should understand how to reconfiger php ini to connect to mysql ,some problems you can dare are
PHP: mysql_connect() won't work via command line
if you put a command like this one i already check via windows cmd and works
c:\xampp\php>php "c:\test\runme.php" yep2
and you are getting "yep2"
as c:\test\ 's runme.bat version :
rem #echo off
set parameter=%1
set PHP_BIN="c:\xampp\php\php.exe"
set script=%cd%\runme.php
%PHP_BIN% %script% %parameter%
and for test we call it in cmd : runme yep2
with the result: yep2
then with the batch modiffied you can fill data in mysql let's say you will call that not runme.php but putmysqldata.php .
at this point creating another file php to read from mysql (even you use only one file php to write or read by calling it by different parameter) so you will be able to read from mysql
so isn't easy if you don't know much vba or how to do it.
following these steps i think if you know some vba more than me you can figure out the shortest way.

PHP show_source not working on my server (Altervista)

I am trying to display the PHP source of a file inside a page. I am using show_source function in this way:
<?php
$nomefile = $_REQUEST['nome'];
show_source($nomefile);
?>
When I try this code on my local PC (using USBWebserver v8.6), it works smoothly, displaying the PHP code of the page. But when I try it on my remote webserver (Altervista), I only get an empty page.
I even try to substitute variable $nomefile with name "visite.php", which is the name of a file residing in the same folder, but still I get no result? I try with echo show_source(...), but no result again.
Is there an error in my code? Or maybe show_source is not compatible with all version of PHP? Is there any easy alternative?
Thanks a lot
Giancarlo Perlo - Italy

Get windows title using php doesn't work on browser call

My problem is I need to fetch FOOBAR2000's title because that including information of playing file, so I create a execute file via Win32 API(GetWindowText(), EnumWindows()) and it's working good.
TCHAR SearchText[MAX_LOADSTRING] = _T("foobar2000");
BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam)
{
TCHAR buffer[MAX_TITLESTRING];
GetWindowText(hwnd, buffer, MAX_TITLESTRING);
if(_tcsstr(buffer, SearchText))
{
// find it output something
}
return TRUE;
}
EnumWindows(WorkerProc, NULL);
Output would look like "album artis title .... [foobar2000 v1.1.5]"
I created a php file like test.php, and use exec() to execute it.
exec("foobar.exe");
then in console(cmd) I use command to execute it
php test.php
It's working good too, same output like before.
Now I use browser(firefox) to call this php file(test.php), strange things happened.
The output only foobar2000 v1.1.5, others information gone ...
I think maybe is exec() problem? priority or some limitation, so I use C# to create a COM Object and register it, and rewrite php code
$mydll = new COM("FOOBAR_COMObject.FOOBAR_Class");
echo $mydll->GetFooBarTitle();
still same result, command line OK, but browser Fail.
My question is
Why have 2 different output between command line and browser. I can't figure it out.
How can I get correct output via browser.
or there is a easy way to fetch FOOBAR2000's title?
Does anyone have experience on this problem?
== 2012/11/28 edited ==
follow Enno's opinion, I modify http_control plug-in to add filename info, original json info is "track title".
modify as following
state.cpp line 380 add 1 line
+pb_helper1 = pfc::string_filename(pb_item_ptr->get_path());
pb_helper1x = xml_friendly_string(pb_helper1);
# 1: when firefox opens the php and it gets executed, it the context depends on the user which runs the php-container (apache), this is quite different from the commandline call which gets executed in your context
# 2 and 3: there seems to be more than one way for getting the title: use the foobar-sdk and create a module which simply reads the current title per api, then write your result in an static-html-document inside your http-root-folder OR use the http-client inside the sdk, with it, you do not need a wabserver, even better use a already implemented module: for instance foo_upnp or foo-httpcontrol
Good luck!
If your webserver runs as a service, in windows you need to enable "allow desktop interaction" for the service. Your php script runs as a child of the webserver process when requested via browser.

Upload file programmatically

Can I programmatically upload a file to the server (without client's interference) ? I know this is not possible in normal (.html) files. Is there anyway I can do it from .hta file? or any server side or plug-gin solution?
from an HTA, you can use the shell object to run commands just as if you were running from the command line - including FTP - but of course you'll need FTP credentials. since you said you'll be able to hardcode the files to be uploaded, i assume you have full access...
var shell = new ActiveXObject('wscript.shell');
var params = // this should be a string of ftp commands, like OPEN ftp.example.com USER PASS CWD somedir PUT c:\whatever.txt BYE
shell.run("%comspec% /c ftp.exe -i -s:" + params, 1, true);
Short answer is no.
It may be possible on some machines using a signed java applet - but from the wording of the question, that's going to be a very long juorney for you.
Based on your last comment, you might atleast need the user to load a web page. So based on an onload function, you can use an ajax hidden form to submit whatever files that you'd want to.
But getting information from your user without their knowledge might put you in a legal situation.
Good luck!!

Categories