I am trying to use sphinx in laravel 5.2 using this library :https://github.com/sngrl/sphinxsearch
I have followed all the steps, changed the ports but I am getting this issue :
ErrorException in SphinxClient.php line 418:Undefined offset: 1
HandleExceptions->handleError('8', 'Undefined offset: 1', '/var/www/html/test/vendor/gigablah/sphinxphp/src/Sphinx/SphinxClient.php', '418', array('errno' => '0', 'errstr' => '', 'host' => 'localhost', 'port' => '5432', 'fp' => resource))
in SphinxClient.php line 418 at SphinxClient->connect() in SphinxClient.php line 1362
I am not sure if the connection set with sphinx is done. Your help will be highly appreciated.
thanks in advance
Harsh Sanghani
After find every where for the issue, I got some luck my combining 2-3 answers.
I have to make some changes in the vendor file :- SphinxClient.php
have to comment out the following code :-
/*
list(, $v) = unpack('N*', fread($fp, 4));
$v = (int) $v;
if ($v < 1) {
fclose($fp);
$this->error = sprintf('expected searchd protocol version 1+, got version \'%d\'', $v);
return false;
}
*/
And add following code before the above commented code :-
$r=unpack ( "N*", fread ( $fp, 4 ) );
if(!isset($r[1])){
fclose ( $fp );
$this->_error = "connected to host, but returned data is not correct";
return false;
}
Now I can not get that error and get the result using sphinx search
Related
i have a new forum up using SMF, and i’m trying to convert the database to UTF-8 now. SMF provides an easy way to do this, but upon doing so, i get this strange sounding error:
you have an error in your sql syntax; check the manual that corresponds to your mariadb server version for the right syntax to use near 'before before blob not null,
change column after after blob not null,
...' at line 6
file: /home/halfmoon/public_html/sources/managemaintenance.php
line: 664
i’m an extreme newbie to coding, especially when it comes to SQL, so i have 0 idea what the error means, other than where to find it and that the line is incorrect. if need be i can also copy and paste the line’s full text here as well- not sure what all is needed!:
line 664 starts at ‘updates_blob’
SQL Vers.:
“
// Change the columns to binary form.
$smcFunc['db_query']('', '
ALTER TABLE {raw:table_name}{raw:updates_blob}',
array(
'table_name' => $table_info['Name'],
'updates_blob' => substr($updates_blob, 0, -1),
)
);
MariaDB Vers.:
// Convert the character set if MySQL has no native support for it.
if (isset($translation_tables[$_POST['src_charset']]))
{
$update = '';
foreach ($table_charsets as $charset => $columns)
foreach ($columns as $column)
$update .= '
' . $column['Field'] . ' = ' . strtr($replace, array('%field%' => $column['Field'])) . ',';
$smcFunc['db_query']('', '
UPDATE {raw:table_name}
SET {raw:updates}',
array(
'table_name' => $table_info['Name'],
'updates' => substr($update, 0, -1),
)
);
}port for it.”
This is very strange: On Windows these functions with exactly the same databases works greats, but when I upload the project to Linux the pageinfo() function returns null. Of course the first thing I thought was that this has to do with case sensitivity, but all seems well formatted...
In my Page Model:
public function pageinfo() {
return $this->hasMany('App\Models\PageToElement', 'page_id');
}
(The Model PageToElement is exactly called like this)
In my controller:
$this->info = Page::find($page->page_id);
$meta = $this->info->pageinfo->where('element_id', 1)->first();
On Windows this nicely returns array:
App\Models\PageToElement Object (
[attributes:protected] => Array(
[id] => 1
[page_id] => 1
[element_id] => 1
[element_parent_id] => 0
[parent_id] => 0
[sorting] => 0
[is_active] => 1
[created_at] => 2015-12-07 10:00:03
[updated_at] => 2015-12-07 10:00:03
)
)
But on Linux, the response is null
What am I overlooking?
After some research, I came to the conclusion that $meta = $this->page->pageinfo->where('element_id', 1)->first(); returns null on the Linux server. But when I do $meta = $this->page->pageinfo; I do get more than one item in return. When I then do $meta = $this->page->pageinfo->first(); it returns one. So I think somehow the where('element_id', 1) is not working for Linux.
But what do you know, $meta = $this->page->pageinfo->where('element_id', '1')->first(); works! element_id is an integer, so why does it need quotes???
But what do you know, $meta = $this->page->pageinfo->where('element_id', '1')->first(); works! But then again not on Windows.
So I wounded up adding an extra line $id = 1; and parsing that in the query.
Strange workaround though
I have a situation while developing an application on Laravel. I have three arrays in the following order. I need to merge them and display their values in the following order too. Here , it goes.
stone_name['ruby','diamond','catseye'];
stone_weight[112,223,445];
stone_rate[1000,2500,670];
I need to merge these three arrays and display the out put in this order.
stone_info = array(stone_name[0] , stone_weight[0] , stone_rate[0]);
So that the final result will be like :
stone_info = array("ruby",112,1000);
I was in the same situation and I had done it in this way. May be this can help you out.
<?php
$stone_name = ['ruby','diamond','catseye'];
$stone_weight = [112,223,445];
$stone_rate = [1000,2500,670];
$result = mergeArrays($stone_name, $stone_weight, $stone_rate);
function mergeArrays($stone_name, $stone_weight, $stone_rate) {
$result = array();
foreach ($stone_name as $key => $name ) {
$result[] = array( 'stone_name' => $name, 'stone_weight' => $stone_weight[$key], 'stone_rate' => $stone_rate[ $key ] );
}
return $result;
}
print_r($result);
Output:
Array
(
[0] => Array
(
[stone_name] => ruby
[stone_weight] => 112
[stone_rate] => 1000
)
[1] => Array
(
[stone_name] => diamond
[stone_weight] => 223
[stone_rate] => 2500
)
[2] => Array
(
[stone_name] => catseye
[stone_weight] => 445
[stone_rate] => 670
)
)
DEMO
Model :
function trans_gdc_add()
{
$trans_gdc_gc_package[0] = $this->input->post('trans_gdc_gc_package');
$trans_gdc_gc_package1 = implode(",", $trans_gdc_gc_package[0]);
$add=array(
'trans_gdc_no' => $this->input->post('trans_gdc_no'),
'trans_gdc_to' => $this->input->post('trans_gdc_to'),
'trans_gdc_vehicle_no' => $this->input->post('trans_gdc_vehicle_no'),
'trans_gdc_vehicle_type' => $this->input->post('trans_gdc_vehicle_type'),
'trans_gdc_vehicle_chas' => $this->input->post('trans_gdc_vehicle_chas'),
'trans_gdc_vehicle_make' => $this->input->post('trans_gdc_vehicle_make'),
'trans_gdc_vehicle_eng' => $this->input->post('trans_gdc_vehicle_eng'),
'trans_gdc_vehicle_permit' => $this->input->post('trans_gdc_vehicle_permit'),
'trans_gdc_vehicle_pol' => $this->input->post('trans_gdc_vehicle_pol'),
'trans_gdc_vehicle_isby' => $this->input->post('trans_gdc_vehicle_isby'),
' trans_gdc_date' => $this->input->post(' trans_gdc_date'),
'trans_gdc_from' => $this->input->post('trans_gdc_from'),
'trans_gdc_driver_add' => $this->input->post('trans_gdc_driver_add'),
'trans_gdc_lic_no' => $this->input->post('trans_gdc_lic_no'),
'trans_gdc_vehilce_owner_name' => $this->input->post('trans_gdc_vehilce_owner_name'),
'trans_gdc_vehicle_owner_add' => $this->input->post('trans_gdc_vehicle_owner_add'),
'trans_gdc_vehicle_owner_mob' => $this->input->post('trans_gdc_vehicle_owner_mob'),
'trans_gdc_broker_name' => $this->input->post('trans_gdc_broker_name'),
'trans_gdc_broker_mob' => $this->input->post('trans_gdc_broker_mob'),
'trans_gdc_gc_no' => $this->input->post('trans_gdc_gc_no'),
'trans_gdc_gc_package' => $trans_gdc_gc_package1,
'trans_gdc_gc_cont' => $this->input->post('trans_gdc_gc_cont'),
'trans_gdc_gc_weight' => $this->input->post('trans_gdc_gc_weight'),
'trans_gdc_gc_freight' => $this->input->post('trans_gdc_gc_freight'),
'trans_gdc_gc_consignor' => $this->input->post('trans_gdc_gc_consignor'),
'trans_gdc_gc_consignee' => $this->input->post('trans_gdc_gc_consignee'),
'status' => '1'
);
return $this->db->insert('trans_gc_add',$add);
}
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: mysql/mysql_driver.php
Line Number: 552
Please help me to resolve this issue .
check this
' trans_gdc_date' => $this->input->post(' trans_gdc_date'),
space might be giving the problem, repla
'trans_gdc_date' => $this->input->post(' trans_gdc_date'),
You can't directly merge strings in arrays!
your trying to merge concatinate strings with arrays or lets say arrays with string thats not possible
General Example
<?php
$stack = array("Orange", "Banane");
array_push($stack, "Apfel", "Himbeere");
print_r($stack);
?>
for your code Example
// array push tiggers a php array as stack!
$add=array()
array_push($add, 'trans_gdc_no', $this->input->post('trans_gdc_no'));
array_push($add, 'trans_gdc_to', $this->input->post('trans_gdc_to'));
print_r($add);
I try to insert a row in the table on code igniter from a Array, but something is going wrong.
That's the array:
Array
(
[Date] => 2001-08-15
[Number] => 962883
[Time] => 17:40
[Etc1] => 0
[Etc2] => 0
)
And this the insert:
$this->db->insert('mytable', $myarray);
A new line is inserted, but all columns are empty!
Trying to find de error, I printed the last query by
echo $this->db->last_query() ." <br>";
And I got:
INSERT INTO `mytable` (`Date`, `Number`, `Time`, `Etc1`, `Etc2`)
VALUES
('\02\00\00\01\0-\00\08\0-\01\05\0', '\09\06\02\08\08\03\0', '\01\07\0:\04\00\0', '\00\0', '\00\0')
For some reason I can not get, the codeigniter ( or PHP ) is wrongly escaping the values.
Any Idea?
Firstly your change your array like this:
$data_array = Array
(
'Date'=> 2001-08-15
'Number' => 962883
'Time' => 17:40
'Etc1' => 0
'Etc2' => 0
);
$this->your_model->insert_data($data_array);
and inside your model write function like this
function insert_data($data=array())
{
$this->db->trans_start();
$this->db->insert('your_table_name',$data);
$this->db->trans_complete();
return TRUE;
}
i hope this will solve your problem
try this , this may help.
$this->db->set('Date', '2001-08-15', FALSE);
$this->db->set('Number', '962883', FALSE);
$this->db->set('Time', '17:40', FALSE);
$this->db->set('Etc1', '0', FALSE);
$this->db->set('Etc2', '0', FALSE);
this->db->insert('mytable');
I tried emulating your problem and was able to get the correct SQL statement genrated.
But I am pasting here the code that worked for me:
$data = array
(
'Date' => '2001-08-15',
'Number' => '962883',
'Time' => '17:40',
'Etc1' => '0',
'Etc2' => '0'
);
$this->db->insert('mytable', $data);
Let me know if this works - and if not, what the error message is.