1

I want update the Postgres database table with array elements but I didn't know how.

I tried this but I got this notice: Notice: Undefined index: 'value' in 'file' on line x

Update:

private function debug ($function_name, $arg_names, $arg_vals (<=with func_get_args())  ) 
{
    $arg_names_array = explode(',', $arg_names);
    foreach($arg_names_array as $k => $v)
    {
        $v = trim($v);
        $v = pg_escape_string($v);
        $vars[$k] = $arg_vals[$v];
    }
    $this->return_ = $vars;
    return $this->return_;  
}
pg_query($connect, "UPDATE tabe SET row = {$vars[$first]}  WHERE code = {$vars[$code]} ");
pg_query($connect, "UPDATE tabe SET row = '{$vars[$first]}'  WHERE code = '{$vars[$code]}' ");

1 Answer 1

0

I need more context information to be able to help you. I understand you want to update a field wich contains an array of values. Remember that in postgresql, the array syntax is {value1,value2,...,valueN}, where value is enclosed in apostrophes if it is a string.

So what does $vars[$first] contain? if it is a php array, you must convert it first to a situable string for the sql command.

2
  • Sorry, the real problem was this: $var[] = $this->return_ . So, right method is $var = $this->return_. Commented Jul 8, 2011 at 12:32
  • Right query: "UPDATE tabe SET row = '{$vars['$first']}' WHERE code = '{$vars['$code']}' "; Commented Jul 8, 2011 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.