Codeigniter showing problem with date function - codeigniter

I want to insert values into db. I have a table as registration_patients. My code is:
$data = array(
'patients_first_name' => $this->input->post('first_name'),
'patients_last_name' => $this->input->post('last_name'),
'patients_email' => $this->input->post('email'),
'patients_password'=> $this->input->post('password'),
'patients_birth_date'=> date('Y-m-d', strtotime($this->input->post('day') . "-" .$this->input->post('month') . "-" . $this->input->post('year'))),
'patients_sex'=> $this->input->post('sex'),
'patients_telephone'=> $this->input->post('telephone'),
'patients_codice_fiscale'=> $this->input->post('codice_fiscale'),
'account_active'=> 0
);
return $this->db->insert('registration_patients', $data);
Now it is inserted values into database bus showing some error and warning like that
A PHP Error was encountered
Severity: Warning
Message: strtotime(): 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 'Europe/London' for
'BST/1.0/DST' instead
Filename: models/doctors_model.php
Line Number: 22 and A PHP Error was encountered
Severity: Warning
Message: date(): 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 'Europe/London' for
'BST/1.0/DST' instead
Filename: models/doctors_model.php
Line Number: 22

In your root_folder/index.php write date_default_timezone_set('America/New_York'); and see if the problem is solved or not. Here is the link of available timezones.

Related

Laravel Illegal operator and value combination on where clause

There are more than 10 controllers in my project. They all have the same code, only the table names are different.
Exactly 2 of these controllers have a problem with the shared host that is 'Illegal operator and value combination'. Surprisingly other controllers works without making such a mistake.
Maybe I overlooked something.
That's where the 'Illegal operator and value combination' problem comes from.
$tarifs = DB::table('tarifs as tarif')
->join('companies as comp', 'tarif.company_id','=', 'comp.id')
->join('categories as cats', 'tarif.catid', '=', 'cats.id')
->where('tarif.company_id', '<', env('COMKEY'))
->get(['tarif.*', 'comp.name', 'comp.photo as cimage','cats.cat_uz']);
Showing this line as an error ->where('tarif.company_id', '<', env('COMKEY'))
This one works without errors.
$minutes = DB::table('minutes as minute')
->join('companies as comp', 'minute.company_id','=', 'comp.id')
->join('categories as cats', 'minute.catid', '=', 'cats.id')
->where('minute.company_id', '<', env('COMKEY'))
->get(['minute.*', 'comp.name', 'cats.cat_uz']);
The project is running normally and without errors on localhost.
Shared and local php versions are the same 7.4
When env('COMKEY') returns the null you will get this error:
InvalidArgumentException with message 'Illegal operator and value combination.'
Code:
$minutes = DB::table('tarifs as tarif')
->join('companies as comp', 'tarif.company_id','=', 'comp.id')
->join('categories as cats', 'tarif.catid', '=', 'cats.id')
->when($comKey,function($query) use ($comKey){
logger()->info('Comkey value is not null',[
'comKey'=> $comKey
]);
return $query->where('tarif.company_id', '<', env('COMKEY'));
},function($query) use ($comKey){
logger()->info('Comkey value is null');
return $query;
})
->dd();
Please use the above query to debug your query.
If the value is returned from env the log will be something like
Comkey value is not null {"comKey":"RandomKey"}
If the value is returned from env the log will be something like:
Comkey value is null

Unable to programmatically create tags in GitHub - ISO8601 timestamp is invalid

In my lumen app I'm trying to programmatically create tags a GitHub repo. My setup is working great except something is up with the tagger.date that I can't figure out. The API is telling me that the timestamp is not valid:
[Github\Exception\RuntimeException]
Invalid request.
2016-07-10T13:32:07+0000 is not a valid date-time.
However the timestamp included in the error message appears to be correctly formatted based on the documentation.
$github->git()->tags()->create(
$githubConfig['namespace'],
$githubConfig['repository'],
[
'tag' => $this->version->patchTag(),
'tagger' => [
'name' => config('github.tagger.name'),
'email' => config('github.tagger.email'),
'date' => Carbon::now()->toIso8601String()
],
'message' => 'This release was automatically published by [Game-Watcher](https://github.com/bkuhl/game-watcher).',
'object' => $masterBranch['commit']['sha'],
'type' => 'commit'
]
);
This fiddle indicates the time format is valid.
Try using Carbon::now()->toAtomString() instead.
Carbon's common formatting methods are "wrappers for the common formats provided in the DateTime class".
The documentation for DateTime::ISO8601 carries this warning:
Note: This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.
The relevant difference appears to be with the timezone offset. DateTime::ISO8601 uses +0000 for UTC, while DateTime::ATOM uses +00:00.

cakePHP 3.0.7 - Unable to call method "" in "default" provider for field "member_selected"

In MembersTable.php I have:
$validator
->notEmpty('member_selected')
->add('member_selected', ['rule' => ['inList', [0,1], false]]);
return $validator;
I am receiving the following very cryptic message from cakePHP 3.0.7
Unable to call method "" in "default" provider for field member_selected" InvalidArgumentException
⟩ Cake\Validation\ValidationRule->process CORE\src\Validation\Validator.php, line 656
⟩ Cake\Validation\Validator->_processRules CORE\src\Validation\Validator.php, line 136
⟩ Cake\Validation\Validator->errors CORE\src\ORM\Marshaller.php, line 181
⟩ Cake\ORM\Marshaller->_validate CORE\src\ORM\Marshaller.php, line 428
⟩ Cake\ORM\Marshaller->merge CORE\src\ORM\Table.php, line 2034
⟩ Cake\ORM\Table->patchEntity APP/Controller\MembersController.php, line 104
⟩ App\Controller\MembersController->edit [internal function]
⟩ call_user_func_array CORE\src\Controller\Controller.php, line 411
⟩ Cake\Controller\Controller->invokeAction CORE\src\Routing\Dispatcher.php, line 114
⟩ Cake\Routing\Dispatcher->_invoke CORE\src\Routing\Dispatcher.php, line 87
⟩ Cake\Routing\Dispatcher->dispatch ROOT\webroot\index.php, line 37
If I remove the ->add('member_selected', ['rule' => ['inList' ...
every thing works ok, but of course the validation is not being done correctly. I do not have an example of the use if 'inList' but I think I've got it setup correctly. I have several other fields of this table that I've had to remove other validator rules from to get past this error message (e.g. naturalNumber).
I also will reference another stackoverflow question titled "cakePHP 3.0.7 - Baked edit function fails to perform save in patchEntity with Marshaller::merge() error."
The problems can be "resolved" by altering the $validator setting for one of the fields... One of ways to create these errors is to change field name or type, and forget to change it in Entity $_accessible, and Table $validator inside function validationDefault(). Also don't forget $rules->adds in Table::buildRules()
Of course... why would anyone want to change a field name or type? Oh well, it would be nice if cakePHP would give some information as to the actual problem (expected field does not exist, or field specified should not exist).
Anyway, now that I've blown off a little steam, the validator is not reporting anything useful when it blows up. I hope someone is watching stackoverflow so it can be resolved.
Having said all this, I'm still wondering why the 'inList' rule does NOT work?
Answer to why inList, and naturalNumber did not work for me!
add public
add( string $field , array|string $name , array|Cake\Validation\ValidationRule $rule [] )
Adds a new rule to a field's rule set. If second argument is an array then rules list for the field will be replaced with second argument and third argument will be ignored.
Example:
$validator
->add('title', 'required', ['rule' => 'notBlank'])
->add('user_id', 'valid', ['rule' => 'numeric', 'message' => 'Invalid User'])
$validator->add('password', [
'size' => ['rule' => ['lengthBetween', 8, 20]],
'hasSpecialCharacter' => ['rule' => 'validateSpecialchar', 'message' => 'not valid']
]);
Well, it's not true! You cannot leave out the second argument! All errors during validation (which are incorrectly reported as far as I'm concerned) go away if I always specify the second arg and then the 3rd arg specifies the rules!
Thanks to everyone who may read and offer assistance,
You forgot to give your rule a 'name' of your own liking
->add('member_selected', 'rule_name', ['rule' => ['inList', [0,1], false]]);

CI_session and Error Number: 1054 (Unknown column ...)

I have got problem with ci_session. When I am creating query with Active Record and I use session, it throws me Error Number: 1054.
It is caused by Session.php . I am using database session and when it executes sess_write(), then it throws error.
Can I create new instance of $this->db ?
Error is at line no. 289 in Session.php
$this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));
In this place is set $this->CI->db->order_by(‘something’), from my code, before I call $this->session and this is my problem.
EDIT (13:12):
Unknown column 'contract.created' in 'order clause'
UPDATE `ci_sessions` SET `last_activity` = 1393330303, `user_data` = 'some_data' WHERE `session_id` = 'ea330d7194f902b6b38b88d509766560' ORDER BY `contract`.`created` DESC LIMIT 30
Filename: C:\Apache24\htdocs\Trokadero_v5\system\database\DB_driver.php
EDIT 2:
I am sure, it is happening by Active Record , because sequence of AR tasks is:
My_controller.php
$this->db->order_by('contract.created', 'DESC');
$this->session->set_flashdata('order_by_direction', 'DESC');
And then is executing in Session.php, with my own order_by clause
$this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));
I got it.
$this->session->userdata();
$this->session->set_userdata();
etc.
MUST BE used before/after execute your own CRUD ($this->db->...).
In your controller, you have to reset the db query.
$this->db->order_by('contract.created', 'DESC');
// add line of code to get data. After getting data, reset the db object.
$this->db->_reset_write();
$this->session->set_flashdata('order_by_direction', 'DESC');

How to properly use Alias in Codeigniter

Here is my code:
$this->db->select('course_name AS Course Name,course_desc AS Course Description,display_public AS Display Status',FALSE);
$this->db->from('courses');
$this->db->where('tennant_id',$tennant_id);
$this->db->order_by('course_name','ASC');
$query = $this->db->get();
and I got an error:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1
and I got an error:
A Database Error Occurred
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1
SELECT course_name AS Course Name,
course_desc AS Course Description,
display_public AS Display Status
FROM (`courses`) WHERE `tennant_id` = 'elicuarto#apploma.com'
ORDER BY `course_name` ASC
Filename: C:\wamp\www\coursebooking\system\database\DB_driver.php
Line Number: 330
Try
$this->db->select('course_name AS `Course Name`, course_desc AS `Course Description`, display_public AS `Display Status`', FALSE);
It's the space in your alias that is messing with you.
UPDATE
I'm not sure why you would want to, but I see nothing preventing you from writing
$this->db->select("course_name AS `{$variable}`", FALSE);
(showing just one field for simplicity)
UPDATE 2
Should be standard string conversion so I don't know why it doesn't work for you.. there's always split strings...
$this->db->select('course_name AS `' . $variable . '`', FALSE);

Resources