Codeigniter Illegal string offset server issue in PostgreSQL query - php

we are using PostGreSql database, when we run following code unit, it shows error of.
Severity: Warning
Message: Illegal string offset 'server'
Filename: postgre/postgre_driver.php
Message: Cannot modify header information - headers already sent by (output started at system/core/Exceptions.php:185)
Model Code:
public function tracks_add( $id ) {
$cnt = 0;
$date = date('Y-m-d H:i:s');
$s_title = $this->input->post('s_title');
$s_singer = $this->input->post('s_singer');
$s_url = $this->input->post('s_url');
foreach ($s_title as $s_title) {
$this->db->set( array('a_id'=> $id, 's_title' => $s_title, 's_singer' => $s_singer[$cnt], 's_url' => $s_url[$cnt], 'date'=> $date) );
$this->db->insert('soundtracks');
$cnt++;
}
}

You can find this issue here :
Postgres db driver insert issue
Change line 331 to
$v = pg_version($this->conn_id); $v = isset($v['server']) ? $v['server'] : 0; // 'server' key

Related

codeigniter update data from excel file (Array to string conversion)

I'm try to update data in oracle table from excel file (.xlsx) use CodeIgniter. I've already uploaded the excel file but when I try to update the data I get the following error message:
Message: Array to string conversion
Filename: database/DB_driver.php
Line Number: 1524
Backtrace:
File: C:\xampp\htdocs\web_excel_ci_test\application\models\RoadmapModel.php
Line: 84
Function: update
File: C:\xampp\htdocs\web_excel_ci_test\application\controllers\Roadmap.php
Line: 209
Function: update_data
Controller:
function update(){
$this->load->library('session');
$fileName = $this->session->flashdata('fileName');
$fileName2 = $this->session->flashdata('fileName2');
include APPPATH.'third_party/PHPExcel/PHPExcel.php';
$excelreader = new PHPExcel_Reader_Excel2007();
$loadexcel = $excelreader->load('excel/'.$fileName);
$sheet = $loadexcel->getActiveSheet()->toArray(null, true, true ,true);
$data = [];
$numrow = 1;
foreach($sheet as $row){
if($numrow > 1){
array_push($data, [
'YEAR'=>$row['A'],
'PROVINCEID'=>$row['B'],
'PROVINCE'=>$row['C'],
'PLAN_A'=>$row['D'],
'ACTUAL_A'=>$row['E'],
]);
}
$numrow++;
}
$year = $this->input->post('YEAR');
$this->RoadmapModel->update_data($year, $fileName2, $data);
redirect("Roadmap");
}
Model:
function update_data($year, $fileName2, $data){
for ($i=0; $i < count($year) ; $i++) {
$this->db->where('YEAR', $year[$i]);
$this->db->update($fileName2, $data);
}
}
i think your $data is a multidimentional array, try to use
$this->db->update_batch
to process batch update. You can also look here to for more options.

500 error when using sqlsrv_get_field on MSSQL smalldatetime

I'm back again with more PHP problems, but this time with the DateTime class.
This is a section of my actual code:
//setup $dbc and $dbcOptions
function test($database, $databaseoptions, $termcode, $department)
{
$tsql = "SELECT StartDate, StopDate
FROM CourseRecords
WHERE TermCode = '" .$termcode. "' AND Department = '" .$department. "';";
$params = array();
$stmt = sqlsrv_query($database, $tsql, $params, $databaseoptions); //---Query ALL the things!!!
if( $stmt === false ) {
echo 'This page is broken<br />';
die( print_r( sqlsrv_errors(), true));
}
return $stmt;
}
$results = test($dbc, $dbcOptions, "142s", "CSC");
$rows = sqlsrv_num_rows($results);
echo "rows = " .$rows;
for ($i = 0; $i < $rows; $i++)
{
if(sqlsrv_fetch($results) !== false)
{
$startdate = date_format(sqlsrv_get_field($results, 0), "Y-m-d"); //line 72
$stopdate = date_format(sqlsrv_get_field($results, 1), "Y-m-d"); //line 73
}
}
I get the following errors in my php-errors.log file:
[13-Nov-2014 17:05:19 UTC] PHP Warning: date_create(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for '-6.0/no DST' instead in E:\inetpub\wwwroot\directory\searchtest.php on line 72
[13-Nov-2014 17:05:19 UTC] PHP Warning: date_create(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Chicago' for '-6.0/no DST' instead in E:\inetpub\wwwroot\directory\searchtest.php on line 73
Creating $startdate and $stopdate as DateTime objects produces the same error when I do this:
$timezone = new DateTimeZone("America/Chicago");
$startdate = new DateTime("2012-12-12", $timezone);
$stopdate = new DateTime("2012-12-12", $timezone);
// get $results and find $rows and junk
$startdate = sqlsrv_get_field($results, 0);
$stopdate = sqlsrv_get_field($results, 1);
which by all means should work because you guys have helped me with previous problems.
So my question is: Why does this fail with a 500 error and what can I do to correct it?
Converting my comment into answer:
Try adding date_default_timezone_set('America/Chicago'); at the beginning of your script.

Yii2 ActiveRecord Setting unknown property: app\models\

This code throw Exception:
public function actionSetdubl() {
$dubls = Yii::$app->request->post('dubl');
$parent = Yii::$app->request->post('parent');
$parentInfo = JurForm::find()->where(['PKJUR' => $parent])->asArray()->all()[0];
for ($i = 0; $i < sizeof($dubls); ++$i) {
$val = $dubls[$i];
$jur = JurForm::findOne($val);
$jur->CFLDUBL = 'Yes';
$jur->DUBLMDM_ID = $parentInfo['MDM_ID'];
$jur->DCHANGEDATE = date('Y-m-d H:i:s');
$jur->save();
}
return Yii::$app->getResponse()->redirect('/index.php?r=jur/analysis');
}
on the line with code $jur = JurForm::findOne($val);.
Exception:
Setting unknown property: app\models\JurForm::PKJUR.
DB: Oracle.
ActiveRecord2 has a hard time automatically mapping table names that start with a capital letter.
So for these columns you have to go into your model class and formally declare them:
public $PKJUR;
maybe better?
$parentInfo = JurForm::find()->where(['PKJUR' => $parent])->asArray()->one()
also i think PKJUR is not defined in DB.

Generate Excel from SQL through PHP

I am using the following code to generate excel from sql through php.this is a modeifed verion of the working code ..
WORKING CODE (NO ERROR)
<?php
//documentation on the spreadsheet package is at:
//http://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.php
chdir('phpxls');
require_once 'Writer.php';
chdir('..');
$sheet1 = array(
array('eventid','eventtitle' ,'datetime' ,'description' ,'notes' ),
array('5' ,'Education Seminar','2010-05-12 08:00:00','Increase your WPM','' ),
array('6' ,'Work Party' ,'2010-05-13 15:30:00','Boss\'s Bday' ,'bring tacos'),
array('7' ,'Conference Call' ,'2010-05-14 11:00:00','access code x4321','' ),
array('8' ,'Day Off' ,'2010-05-15' ,'Go to Home Depot' ,'' ),
);
$sheet2 = array(
array('eventid','funny_name' ),
array('32' ,'Adam Baum' ),
array('33' ,'Anne Teak' ),
array('34' ,'Ali Katt' ),
array('35' ,'Anita Bath' ),
array('36' ,'April Schauer'),
array('37' ,'Bill Board' ),
);
$workbook = new Spreadsheet_Excel_Writer();
$format_und =& $workbook->addFormat();
$format_und->setBottom(2);//thick
$format_und->setBold();
$format_und->setColor('black');
$format_und->setFontFamily('Arial');
$format_und->setSize(8);
$format_reg =& $workbook->addFormat();
$format_reg->setColor('black');
$format_reg->setFontFamily('Arial');
$format_reg->setSize(8);
$arr = array(
'Calendar'=>$sheet1,
'Names' =>$sheet2,
);
foreach($arr as $wbname=>$rows)
{
$rowcount = count($rows);
$colcount = count($rows[0]);
$worksheet =& $workbook->addWorksheet($wbname);
$worksheet->setColumn(0,0, 6.14);//setColumn(startcol,endcol,float)
$worksheet->setColumn(1,3,15.00);
$worksheet->setColumn(4,4, 8.00);
for( $j=0; $j<$rowcount; $j++ )
{
for($i=0; $i<$colcount;$i++)
{
$fmt =& $format_reg;
if ($j==0)
$fmt =& $format_und;
if (isset($rows[$j][$i]))
{
$data=$rows[$j][$i];
$worksheet->write($j, $i, $data, $fmt);
}
}
}
}
$workbook->send('test.xls');
$workbook->close();
//-----------------------------------------------------------------------------
?>
MODIFIED CODE TO RETRIEVE DATA FROM DATABASE (WHICH SHOWS ERROR)
<?php
$numrow12 = mysql_query("SELECT * FROM mastertable WHERE pdfstatus = 1 ORDER BY tstamp DESC");
mysql_select_db("brainoidultrafb", $link);
chdir('phpxls');
require_once 'Writer.php';
chdir('..');
while($row = mysql_fetch_array($numrow12)) {
$sheet1 = array(
array('StudentID','Students Email' ,'Diagnosis','TimeStamp' ,),
array($row['student_id'] ,$row['email_id'],$row['diagnosis'],$row['tstamp'],),
);
}
$workbook = new Spreadsheet_Excel_Writer();
$format_und =& $workbook->addFormat();
$format_und->setBottom(2);//thick
$format_und->setBold();
$format_und->setColor('black');
$format_und->setFontFamily('Arial');
$format_und->setSize(8);
$format_reg =& $workbook->addFormat();
$format_reg->setColor('black');
$format_reg->setFontFamily('Arial');
$format_reg->setSize(8);
$arr = array(
'Calendar'=>$sheet1,
);
foreach($arr as $wbname=>$rows)
{
$rowcount = count($rows);
$colcount = count($rows[0]);
$worksheet =& $workbook->addWorksheet($wbname);
$worksheet->setColumn(0,0, 6.14);//setColumn(startcol,endcol,float)
$worksheet->setColumn(1,3,15.00);
$worksheet->setColumn(4,4, 8.00);
for( $j=0; $j<$rowcount; $j++ )
{
for($i=0; $i<$colcount;$i++)
{
$fmt =& $format_reg;
if ($j==0)
$fmt =& $format_und;
if (isset($rows[$j][$i]))
{
$data=$rows[$j][$i];
$worksheet->write($j, $i, $data, $fmt);
}
}
}
}
$workbook->send('Submissions.xls');
$workbook->close();
//-----------------------------------------------------------------------------
?>
Its showing the following errors
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/content/58/9508458/html/psychiatric/subexcel.php on line 13
Warning: Cannot modify header information - headers already sent by (output started at /home/content/58/9508458/html/psychiatric/subexcel.php:13) in /home/content/58/9508458/html/psychiatric/phpxls/Writer.php on line 67
Warning: Cannot modify header information - headers already sent by (output started at /home/content/58/9508458/html/psychiatric/subexcel.php:13) in /home/content/58/9508458/html/psychiatric/phpxls/Writer.php on line 68
Warning: Cannot modify header information - headers already sent by (output started at /home/content/58/9508458/html/psychiatric/subexcel.php:13) in /home/content/58/9508458/html/psychiatric/phpxls/Writer.php on line 69
Warning: Cannot modify header information - headers already sent by (output started at /home/content/58/9508458/html/psychiatric/subexcel.php:13) in /home/content/58/9508458/html/psychiatric/phpxls/Writer.php on line 70
Warning: Cannot modify header information - headers already sent by (output started at /home/content/58/9508458/html/psychiatric/subexcel.php:13) in /home/content/58/9508458/html/psychiatric/phpxls/Writer.php on line 71
Right now, you're selecting the database after you try to query the database:
$numrow12 = mysql_query("SELECT * FROM mastertable WHERE pdfstatus = 1 ORDER BY tstamp DESC");
mysql_select_db("brainoidultrafb", $link);
That won't work. Just swap the order so you select the database, then query it:
mysql_select_db("brainoidultrafb", $link);
$numrow12 = mysql_query("SELECT * FROM mastertable WHERE pdfstatus = 1 ORDER BY tstamp DESC");
As for your second problem, you're overwriting $sheet1 on each iteration of the loop. Do this instead:
$sheet1 = array(
array('StudentID','Students Email' ,'Diagnosis','TimeStamp' ,)
);
while($row = mysql_fetch_array($numrow12)) {
$sheet1[] = array($row['student_id'], $row['email_id'], $row['diagnosis'], $row['tstamp'],);
}
For your second problem use:
$sheet1[] =
To append elements to the $sheet1 array. You're currently replacing it after every iteration of the loop.
You'll probably want to initialize $sheet1 outside of the while loop to avoid warnings as well. $sheet1 = array();

PHP Cannot use string offset as an array Error

I'm trying to retrieve tasks from Rembmer the Milk API. I run this code:
$array = json_decode($content, true);
foreach($array['rsp']['tasks']['list']['taskseries'] as $keys=>$val) {
$task = $val['name'];
$duedate = $val['task']['due'];
echo $task." ";
echo $duedate."<br>";
}
but I am getting this error:
Fatal error: Cannot use string offset as an array in C:** on line 66
(line 66 being $duedate = $val['task']['due'];)
This is the JSON response I am trying to decode (trying to get "name":"SOMETHING" and "due":"2011-03-17T04:00:00Z":
{"rsp":{"stat":"ok","tasks":{"rev":"[CODE]","list":{"id":"[ID NUMBER]","taskseries": {"id":"ID","created":"DATE CREATED","modified":"DATE","name":"SOMETHING","source":"js","url":"","location_id":"","tags":[],"participants":[],"notes":[],"task":{"id":"ID","due":"2011-03-17T04:00:00Z","has_due_time":"0","added":"DATE","completed":"","deleted":"","priority":"1","postponed":"0","estimate":""}}}}}}
How to fix?
Thanks!!!!!
UPDATE
This is the JSON response for two or more tasks:
{"rsp":{"stat":"ok","tasks":{"rev":"NUMBER","list":{"id":"ID NUMBER","taskseries":[{"id":"ID NUMBER","created":"CREATED DATE","modified":"DATE","name":"TASK 3","source":"js","url":"","location_id":"","tags":[],"participants":[],"notes":[],"task":{"id":"ID","due":"2011-03-18T04:00:00Z","has_due_time":"0","added":"DATE","completed":"","deleted":"","priority":"1","postponed":"0","estimate":""}},{"id":"ID","created":"DATE","modified":"DATE","name":"SOMETHING","source":"js","url":"","location_id":"","tags":[],"participants":[],"notes":[],"task":{"id":"ID","due":"2011-03-17T04:00:00Z","has_due_time":"0","added":"DATE","completed":"","deleted":"","priority":"1","postponed":"0","estimate":""}}]}}}}
Try this:
$taskSeries=$array['rsp']['tasks']['list']['taskseries'];
if(array_key_exists('id', $taskSeries)) {
$taskSeries=array($taskSeries);
}
foreach($taskSeries as $task) {
$name=$task['name'];
$due=$task['task']['due'];
// do something with $name and $due here
}

Categories