{"id":19,"date":"2013-11-12T15:16:41","date_gmt":"2013-11-12T20:16:41","guid":{"rendered":"http:\/\/www.scalemysql.com\/blog\/?p=19"},"modified":"2013-11-12T18:07:55","modified_gmt":"2013-11-12T23:07:55","slug":"handlersocket-syntax-examples","status":"publish","type":"post","link":"https:\/\/www.scalemysql.com\/?p=19","title":{"rendered":"Handlersocket Part III \/ examples \/ Perl"},"content":{"rendered":"<p>(originally posted 07\/18\/12)<\/p>\n<p>other handlersocket entries:<\/p>\n<p><strong>part I<\/strong> &#8211; <a title=\"introduction to handlersocket\" href=\"http:\/\/www.scalemysql.com\/blog\/2013\/11\/12\/introduction-to-handlersocket\/\">introduction to handlersocket<\/a><\/p>\n<p><strong>part II<\/strong> &#8211; <a title=\"handlersocket examples\" href=\"http:\/\/www.scalemysql.com\/blog\/2013\/11\/12\/handlersocket-syntax-perl\/\">handlersocket syntax Perl\/PHP<\/a><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n<p><strong>Inserting Records<\/strong><\/p>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #993366; text-decoration: underline;\">Single record<\/span><\/span><\/p>\n<pre>$res = $hs-&gt;execute_single(0, '+', ['mike','mike@101.com','2011-05-03']\r\n, 1, 0);\r\n\r\n\u00a0die $hs-&gt;get_error() if $res != 0;<\/pre>\n<p><span style=\"text-decoration: underline; color: #993366;\">Multiple records<\/span><\/p>\n<p>let\u2019s insert four more records as a \u2018batch\u2019<\/p>\n<pre style=\"padding-left: 30px;\">$res = $hs-&gt;execute_multi([\r\n [0, '+', ['102','bob','bob@102.com','2011-12-29'], 1, 0],\r\n [0, '+', ['103','john','john@103.com','2011-07-18'], 1, 0],\r\n [0, '+', ['104','jane','jane@104.com','2011-06-23'], 1, 0],\r\n [0, '+', ['105','dave','dave@105.com','2011-04-12'], 1, 0]\r\n ]);<\/pre>\n<pre style=\"padding-left: 60px;\">for my $res (@$res) {\r\n die $hs-&gt;get_error() if $res-&gt;[0] != 0;\r\n shift(@$res);<\/pre>\n<p>note: Limit and offset do not affect the insert.<\/p>\n<p><strong>Reading Records<\/strong><\/p>\n<p>For reading records, you\u2019ll want to additionally do something with the resulting array reference.<\/p>\n<p>Something like this will work,<\/p>\n<pre style=\"padding-left: 60px;\">for (my $row = 0; $row &lt; $ele_returned; $row+= $count_cols) {\r\n   if($res-&gt;[$row]){\r\n      my $user_name= $res-&gt;[$row + 0];\r\n      my $user_email= $res-&gt;[$row + 1];\r\n      my $created= $res-&gt;[$row + 2];\r\n      print \"$user_name | $user_email | $created\\n\";\r\n   }\r\n}<\/pre>\n<p><span style=\"text-decoration: underline; color: #993366;\">Exact values<\/span><\/p>\n<p><strong>a)<\/strong> Selecting on an exact single value<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=', ['102'], 1, 0);<\/pre>\n<p><strong>b)<\/strong> selecting on two or more exact values (where col1=a AND col2=b)<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=', ['102', \u2018mike\u2019], 1, 0);<\/pre>\n<p>note: select on two keys must have the multiple index to support it<\/p>\n<p><strong>c)<\/strong> selecting on two or more exact values (where col1=a or col2=b)<\/p>\n<pre>$res = $hs-&gt;execute_multi(\r\n[0, '=', ['102'], 1, 0],\r\n[1, '=', ['mike'], 1, 0]\r\n);<\/pre>\n<p>note the second array needed to use a different index<br \/>\nnotes:<\/p>\n<p>handlersocket needs indexes to find results and like mysql, a multi-column index requires the leftmost prefix and index. Again, handlesocket does not do table scans, and so without it, you will not get any results at all.<\/p>\n<p><strong>d)<\/strong> Selecting on one or more values with (where col1 in (a, b, c\u2026.))<\/p>\n<p>You can do this one of two ways,<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_multi(\r\n [0, '=', ['101'], 1, 0],\r\n [0, '=', ['102'], 1, 0],\r\n [0, '=', ['103'], 1, 0],\r\n [0, '=', ['105'], 1, 0]\r\n);<\/pre>\n<p>or<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=',[''], 1, 0,\r\nundef,undef,undef,0,['101','102','103','105']);<\/pre>\n<p>note with the second query, we can do more with it later on such as filtering while in the first query the arrays are independent of one another..<\/p>\n<p><span style=\"text-decoration: underline; color: #993366;\">Limits and Offsets<\/span><\/p>\n<p>These are very straight forward, we\u2019ll start with a limit of 10,more than enough for our 5 records. (where col1=a limit x,y)<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;=', ['101'], 10, 0);<\/pre>\n<p style=\"padding-left: 60px;\">101 | mike | mike@101.com<br \/>\n102 | bob | bob@102.com<br \/>\n103 | john | john@103.com<br \/>\n104 | jane | jane@104.com<br \/>\n105 | dave | dave@105.com<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;=', ['101'], 3, 0);<\/pre>\n<p style=\"padding-left: 60px;\">101 | mike | mike@101.com<br \/>\n102 | bob | bob@102.com<br \/>\n103 | john | john@103.com<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;=', ['101'], 10, 2);<\/pre>\n<p style=\"padding-left: 60px;\">103 | john | john@103.com<br \/>\n104 | jane | jane@104.com<br \/>\n105 | dave | dave@105.com<\/p>\n<p><span style=\"text-decoration: underline; color: #993366;\">Range Searches<\/span><\/p>\n<p>handlersocket is a little odd in that only one boundary of a range search can be specified in the initial operator cell<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;', ['102'], 10, 0);<\/pre>\n<p style=\"padding-left: 60px;\">103 | john | john@103.com<br \/>\n104 | jane | jane@104.com<br \/>\n105 | dave | dave@105.com<\/p>\n<p>two bounded range can indeed be done, it can be done with an additional filter function, (W for a stop, F for a filter of those records)<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;',['102'], 10, 0, undef, undef,\r\n[['W','execute_single(0, '&gt;',['102'], 10, 0, undef, undef,\r\n[['F','!=', '0','104']]);<\/pre>\n<p style=\"padding-left: 60px;\">103 | john | john@103.com<br \/>\n105 | dave | dave@105.com<\/p>\n<p>the filter can be a different column as well,<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;',['102'], 10, 0, undef, undef,\r\n[['F','=', '1','dave']]);<\/pre>\n<p style=\"padding-left: 60px;\">105 | dave | dave@105.com<\/p>\n<p>as you can see with the ability to adjust operations, filters and columns, there are lots of combinations<\/p>\n<p><strong>updating records<\/strong><\/p>\n<p>similar to the selects, the key difference being an update \u2018U\u2019 flag and array of columns are specified.<\/p>\n<p><span style=\"text-decoration: underline; color: #993366;\">a single key<\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=', ['103'], 1, 0, 'U',\r\n['2015-12-12 00:00:00']);<\/pre>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #993366; text-decoration: underline;\">a range<\/span><\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;=', ['103'], 1, 0, 'U',\r\n['2015-12-12 00:00:00']);<\/pre>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #993366; text-decoration: underline;\">two keys<\/span><\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=', ['102', 'mike'], 1, 0, 'U',\r\n['2015-12-12 00:00:00']);<\/pre>\n<p><span style=\"text-decoration: underline; color: #993366;\">a range and filter<\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;',['102'], 10, 0, 'U',\r\n['2015-12-12 00:00:00'], ['F','=', '1','dave']);<\/pre>\n<p><span style=\"color: #cc0000;\">This is not working correctly.<\/span><\/p>\n<p><span style=\"text-decoration: underline; color: #993366;\">an \u2018IN\u2019 and filter<\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=',[''], 10, 0, 'U',\r\n['2015-12-12 00:00:00'],[['F','!=', 'mike']],0,\r\n['101','102','103','104']);<\/pre>\n<p>it\u2019s important the columns in the open_index call are exactly the same as in your update statement<\/p>\n<p><strong>Deleting Records<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 30px;\"><span style=\"text-decoration: underline; color: #993366;\">Single record<\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=', ['103'], 1 , 0, 'D');<\/pre>\n<p style=\"padding-left: 60px;\">+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| user_id | user_name | user_email | created |<br \/>\n+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| 101 | mike | mike@101.com | 2011-05-03 00:00:00 |<br \/>\n| 102 | bob | bob@102.com | 2011-12-29 00:00:00 |<br \/>\n| 104 | jane | jane@104.com | 2015-12-12 00:00:00 |<br \/>\n| 105 | dave | dave@105.com | 2015-12-12 00:00:00 |<br \/>\n+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<\/p>\n<p><span style=\"text-decoration: underline; color: #993366;\">multiple records<\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;=', ['103'],10 , 0, 'D');<\/pre>\n<p style=\"padding-left: 60px;\">+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| user_id | user_name | user_email | created |<br \/>\n+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| 101 | mike | mike@101.com | 2011-05-03 00:00:00 |<br \/>\n| 102 | bob | bob@102.com | 2011-12-29 00:00:00 |<br \/>\n+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;=', ['103'], 2, 2 'D');<\/pre>\n<p style=\"padding-left: 60px;\">+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| user_id | user_name | user_email | created |<br \/>\n+&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| 101 | mike | mike@101.com | 2011-05-03 00:00:00 |<br \/>\n| 104 | jane | jane@104.com | 2011-06-23 00:00:00 |<br \/>\n| 105 | dave | dave@105.com | 2011-04-12 00:00:00 |<\/p>\n<p>You can not seem to use or even accept \u2018!=\u2019<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '!=', ['103'], 10, 0, 'D');<\/pre>\n<p>however the filter can be made to do the same thing<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;=',['101'], 10, 0, 'D',\r\nundef,[['F','!=', '1','bob']]);<\/pre>\n<p style=\"padding-left: 60px;\">| 102 | bob | bob@102.com | 2011-12-29 00:00:00 |<\/p>\n<p><span style=\"text-decoration: underline; color: #993366;\">filters and IN<\/span><\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=',[''], $rows_returned, $offset,\r\n'D', undef,[['F','!=', '1','bob']],0,['101','102','103','104']);<\/pre>\n<p style=\"padding-left: 60px;\">| 102 | bob | bob@102.com | 2011-12-29 00:00:00 |<br \/>\n| 105 | dave | dave@105.com | 2011-04-12 00:00:00 |<\/p>\n<p><strong>bugs<\/strong> (tested around 02-15-12)<\/p>\n<p>a recent fix was implemented for filtering and \u2018IN\u2019 in combination, however,<\/p>\n<p>you CAN NOT seem to use a range, filter and \u2018IN\u2019 statement at the same time, such as,<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '&gt;',['101'], 10, 0, undef, undef,\r\n[['F','!=', '1','bob']],0,['101','102','103','104']);<\/pre>\n<p style=\"padding-left: 60px;\">103 | john | john@103.com<br \/>\n104 | jane | jane@104.com<br \/>\n105 | dave | dave@105.com <span style=\"color: #ff0000;\">X<\/span><\/p>\n<p>I had problems with the date field as well with just filtering and IN,<\/p>\n<pre style=\"padding-left: 60px;\">$res = $hs-&gt;execute_single(0, '=',[''], 10, 0, undef, undef,\r\n[['F','&gt;', '2','2011-07-18 00:00:00']],0,['101','102','103','104']);<\/pre>\n<p style=\"padding-left: 60px;\">101 | mike | mike@101.com <span style=\"color: #ff0000;\">X<\/span><br \/>\n102 | bob | bob@102.com<br \/>\n103 | john | john@103.com <span style=\"color: #ff0000;\">X<\/span><br \/>\n104 | jane | jane@104.com <span style=\"color: #ff0000;\">X<\/span><\/p>\n<p>as with the selects, all three (range, filters and IN) do not all work together<\/p>\n<p style=\"padding-left: 60px;\">| 101 | mike | mike@101.com | 2011-05-03 00:00:00 |<br \/>\n| 102 | bob | bob@102.com | 2011-12-29 00:00:00 |<\/p>\n<p>(missing 105 from the IN exclusion)<\/p>\n<p><strong>putting it all together<\/strong><\/p>\n<p>here is a sample script in perl<\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#!\/usr\/bin\/perl<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #888888;\">### this script is far from optimized, particularly for many returned rows, however you probably shouldn&#8217;t be using handlersocket for a lot of return data anyways,<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">use strict;<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">use warnings;<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">use Net::HandlerSocket; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#1. establishing a connection <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">####### port 9999 to write, 9998 to read <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#my $args = { host =&gt; &#8216;127.0.0.1&#8217;, port =&gt; 9998 };<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> my $args = { host =&gt; &#8216;127.0.0.1&#8217;, port =&gt; 9999 }; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my $hs = new Net::HandlerSocket($args); <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#2. initializing an index so that we can use in main logics.<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"># MySQL tables will be opened here (if not opened) <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my $res = $hs-&gt;auth(&#8216;secretwr&#8217;);<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> die $hs-&gt;get_error() if $res != 0; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">## no spaces or it will error<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> my $cols = &#8220;user_name,user_email,created&#8221;; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">### used to get the count of the columns above dynamically, need for below <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my @count_cols = split(\/,\/,$cols);<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my $count_cols = scalar(@count_cols); <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">$res = $hs-&gt;open_index(1, &#8216;test&#8217;, &#8216;user&#8217;, &#8216;user_name&#8217;, $cols);<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">die $hs-&gt;get_error() if $res != 0; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#3. main logic my $rows_returned = 3;<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my $offset = 0;<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my $ele_returned = $rows_returned * $count_cols; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#select signs can be &#8211; &#8216;=&#8217;, &#8216;&gt;&#8217;,'&lt;&#8216;,'&lt;=&#8217;,&#8217;&gt;=&#8217;, &#8216;!=&#8217; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">$res = $hs-&gt;execute_single(1, &#8216;&gt;=&#8217;, [&#8216;101&#8217;], $rows_returned, $offset);<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">die $hs-&gt;get_error() if $res-&gt;[0] != 0;<\/span> <span style=\"color: #5494ab;\"> shift(@$res); <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">########### multi-select <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#$res = $hs-&gt;execute_multi([<\/span> <span style=\"color: #5494ab;\"> #[1, &#8216;=&#8217;, [&#8216;mike&#8217;], 1, 0], [1, &#8216;=&#8217;, [&#8216;jane&#8217;], 1, 0]<\/span> <span style=\"color: #5494ab;\"> #]); <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">## this begins the exec for a multi-statement<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#for my $res (@$res) {<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> #\u00a0\u00a0\u00a0 die $hs-&gt;get_error() if $res-&gt;[0] != 0;<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#\u00a0\u00a0\u00a0 shift(@$res); my $count_elements = scalar(@$res);<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my $count_rows = $count_elements \/ $count_cols; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">for (my $row = 0; $row &lt; $ele_returned; $row+= $count_cols) { <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">if($res-&gt;[$row]){<\/span> <span style=\"color: #5494ab;\"> my $user_name= $res-&gt;[$row + 0];<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> my $user_email= $res-&gt;[$row + 1];<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">my $created= $res-&gt;[$row + 2];<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">print &#8220;$user_name | $user_email | $created\\n&#8221;;<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> }<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> } <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">print&#8221;elements: $count_elements\\n&#8221;;<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"> print &#8220;rows: $count_rows\\n\\n&#8221;; <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">### this is the closing bracket for a multi-statment<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\"># } <\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">#4. closing the connection<\/span><\/p>\n<p style=\"padding-left: 60px;\"><span style=\"color: #5494ab;\">$hs-&gt;close();<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(originally posted 07\/18\/12) other handlersocket entries: part I &#8211; introduction to handlersocket part II &#8211; handlersocket syntax Perl\/PHP &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Inserting Records Single record $res = $hs-&gt;execute_single(0, &#8216;+&#8217;, [&#8216;mike&#8217;,&#8217;mike@101.com&#8217;,&#8217;2011-05-03&#8242;] , 1, 0); \u00a0die $hs-&gt;get_error() if $res != 0; Multiple records let\u2019s insert four more records as a \u2018batch\u2019 $res = $hs-&gt;execute_multi([ [0, &#8216;+&#8217;, [&#8216;102&#8242;,&#8217;bob&#8217;,&#8217;bob@102.com&#8217;,&#8217;2011-12-29&#8242;], 1, 0], [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19"}],"version-history":[{"count":40,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":238,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions\/238"}],"wp:attachment":[{"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalemysql.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}