PHP code example of tz-lom / hsphp

1. Go to this page and download the library: Download tz-lom/hsphp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tz-lom / hsphp example snippets


$c = new \HSPHP\ReadSocket();
$c->connect();
$id = $c->getIndexId('data_base_name', 'table_name', '', 'id,name,some,thing,more');
$c->select($id, '=', array(42)); // SELECT WITH PRIMARY KEY
$response = $c->readResponse();

//SELECT with IN statement
$c = new \HSPHP\ReadSocket();
$c->connect();
$id = $c->getIndexId('data_base_name', 'table_name', '', 'id,name,some,thing,more');
$c->select($id, '=', array(0), 0, 0, array(1,42,3));
$response = $c->readResponse();

$c = new \HSPHP\WriteSocket();
$c->connect('localhost',9999);
$id = $c->getIndexId('data_base_name','table_name','','k,v');
$c->update($id,'=',array(100500),array(100500,42)); // Update row(k,v) with id 100500 to  k = 100500, v = 42
$response = $c->readResponse(); // Has 1 if OK

$c = new \HSPHP\WriteSocket();
$c->connect('localhost',9999);
$id = $c->getIndexId('data_base_name','table_name','','k,v');
$c->update($id,'=',array(100500),array(100500,42), 2, 0, array(100501, 100502)); // Update rows where k IN (100501, 100502)
$response = $c->readResponse(); // Has 1 if OK

$c = new \HSPHP\WriteSocket();
$c->connect('localhost',9999);
$id = $c->getIndexId('data_base_name','table_name','','k,v');
$c->delete($id,'=',array(100500));
$response = $c->readResponse(); //return 1 if OK

$c = new \HSPHP\WriteSocket();
$c->connect('localhost',9999);
$id = $c->getIndexId('data_base_name','table_name','','k,v');
$c->insert($id,array(100500,'test\nvalue'));
$response = $c->readResponse(); //return array() if OK

$c = new \HSPHP\WriteSocket();
$c->connect('localhost',9999);
$id = $c->getIndexId('data_base_name','table_name','','v');
$c->increment($id,'=',array(100500),array(2)); // Increment v column by 2
$response = $c->readResponse(); // Has 1 if OK

$c = new \HSPHP\WriteSocket();
$c->connect('localhost',9999);
$id = $c->getIndexId('data_base_name','table_name','','v');
$c->decrement($id,'=',array(100500),array(2)); // Decrement v column by 2
$response = $c->readResponse(); // Has 1 if OK