Model Auto Increment Number Issue.. After 1,000 Records - php

Please help me to fix this issue as i am getting it from today morning... After doing some research i have found the issue...
I have a table called... "fmb_form_item_answer"
currently this table is.. having 1079 records
Name of the Model is... "FmbFormItemAnswer"
the issue is, after reaching 999th record.. when i access model->id it gives a text instead of int... as 1,002
for example..
when when model->id = 1079, it generates... 1,079 (with comma after 1)
I was able to figure this out after checking the DB logs... below is what i found..
2013-08-19 18:59:53 EST ERROR: invalid input syntax for integer: "1,079"
2013-08-19 18:59:53 EST STATEMENT: SELECT * FROM "fmb_form_item_answer" WHERE submission_id=$1
please can some expert help me to resolve this issue. its a coming up from a production server.. so any quick help is greatly appreciated...
i tried... this way too....
setting a rule in model....
array('id', 'numerical'),
Screenshot

Plese check weather u have number_format() php function enabled somewhere.. if so that could be the reason...
If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.
ref : http://php.net/manual/en/function.number-format.php

Related

Select month from a date field in laravel

I'm trying to perform a query in Laravel 7 that gets the month part of a date field. I tried the following queries
$test = MyModal::selectRaw('month("date_col") as temp')->get();
$test = MyModal::select(DB::Raw('month("date_col") as temp'))->get();
$test = DB::table('my_table')->select('month("date_col") as temp')->get();
All variation of the same query. If I dump the query log, the query is correct for all 3
select month("date_col") as temp from "my_table"
If I run this on my DB I get the result as well. But I keep getting this error in laravel:
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such function: month (SQL: select month("date_col") as temp from "my_table")
Am I doing something wrong? And is there a way to do this query in laravel?
Edit: Sorry forgot to mention this is with Laravel's unit testing
I think the problem in the way you use Month function
you don't set quotations for the column name, it should be:
$test = MyModal::selectRaw('month(date_col) as temp')->get();
it should work
You can do something like this:
MyModal::select(DB::raw("MONTH(date_col) month"))->get();
Thanks to OMR's comment this solution finally worked
$test = MyModel::selectRaw('strftime("%m", "date_col") as temp')->get();
Update: It looks like what I had in the beginning worked fine and the unit test was the only part throwing this error. Since I was working with mysql while the test environment was using sqlite which apparently doesnt like the "month()" function which OMR did point out in his comment. So this solution works in the test but not in live. Couldn't figure out how to change the test environment to use in memory mysql instead of sqlite. If anyone knows how to please add an answer here.

PHP Atlas.ORM returns always the same result

I want to load data from a SQLite database in PHP using Atlas.Orm.
When I run the following snippet, I get a set of 1773 results, but each result is the same!
$atlas = Atlas::new('sqlite:[Path To Database]');
$result = $atlas->select(Stop::class)->fetchRecords();
Can anyone tell me whats wrong here?
After several hours of desperation, I found the issue by myself. The ORM needs the PRIMARY_KEY constant in the corresponding *Table class to be set, otherwise fetching records will fail like this.

PHP interprets Query Result as 0

I have come across a strange problem, which im trying to solve for quite some time now but can´t find any solution to this.
I am generating some lines with information which each of includes one checkbox. I have the following code in PHP which checks if a certrain entry exists, if so the checkbox is checked.
$sql = "SELECT COUNT(*) anz FROM jubilaeum WHERE jahr='".$Jahr."' AND mon='".$num."' AND AdrNr='".$RS1_row["AdrNr"]."' AND type='1'";
$rs_erledigt = $db->prepare($sql);
$rs_erledigt->execute();
$row = $rs_erledigt->fetch();
$anz = $row["anz"];
The Code generates me the following SQL Query:
SELECT COUNT(*) anz FROM jubilaeum WHERE jahr='2019' AND mon='5' AND AdrNr='14061' AND type='1'
PHPMyAdmin Query & Result
Now i am using a basic IF to check if there are any records found so i can check a checkbox
<input type="checkbox" name="mychk" id="mychk" value="somevalue" <?php if($anz>0) echo "checked"; ?> />
All checkboxes which have a proper entry in my DB are checked, except the very first one generated, i can swap the boxes around at free will, the first one never gets checked.
I tried to use the $row["Anz"] directly in my IF, didn´t fix the problem.
I think that PHP doesnt interpret the returned value of my query correctly, but i am clueless about how to fix this.
Did someone encounter similar problems and can help me with this?
Im new to posting in here, so please tell me if you need some more information.
Thanks in advance!
Edit: I just tried to change the Query from COUNT(*) to if(COUNT(*)>0,'ja','nein') while also changing the if to if($anz=="ja")
the value of $anz still remains empty.
I found the solution. My issue was a second fetch on my Query. After removing it, everything works fine.

Propel Criteria NOT LIKE with wild card not working for date time column

I am trying to run following query. But it gives following error. Please advice me if there is any alternative way to do that.
$resource_query = AgentsCdr::create()
->withColumn('(UNIX_TIMESTAMP(AgentsCdr.PickupTime)-UNIX_TIMESTAMP(AgentsCdr.Calldate))', 'waittime')
->withColumn('(UNIX_TIMESTAMP(AgentsCdr.LastHangup)-UNIX_TIMESTAMP(AgentsCdr.Calldate))', 'waittime2')
->filterByCalldate("$sdate $stime",Criteria::GREATER_EQUAL)
->filterByCalldate("$edate $etime",Criteria::LESS_EQUAL)
//here is the issue occurs. Because of 2017-08-09%
->filterByCalldate("2017-08-09%",Criteria::NOT_LIKE);
Returning error is [message:protected] => Error parsing date/time value: '2017-08-09%'
Can you please suggest me a solution for this. Thank you.

Date Insertion Issue in Oracle Database and Codeigniter

I am having a problem in updating oracle db table with date column . I have tried many solutions but still not working. I can not insert the date into the database using codeigniter active record or normal query.. the column type is Timestamp. here are some solutions I have tried. could u help please.. thank you
$this->db->set('AC_START',"TO_DATE('2014-03-4 2:30','yyyy-mm-dd hh:mm')");
$this->db->set('AC_END',"TO_DATE('2014-05-5 2:34' ,'yyyy-mm-dd hh:mm')");
$this->db->insert('ACTIVITES');
here is error message that I always get
Error Number:
INSERT INTO "LI_PPPA"."ACTIVITES" ("AC_START", "AC_END") VALUES ('TO_DATE('2014-03-4 2:30','yyyy-mm-dd hh:mm')', 'TO_DATE('2014-05-5 2:34' ,'yyyy-mm-dd hh:mm')')
Filename: Directory\program\system\database\DB_driver.php
Line Number: 330
You have to make sure CI doens't escape the values you are passing to the oracle database, because to_date is an oracle function.
Try the following:
$this->db->set('AC_START',"TO_DATE('2014-03-4 2:30','yyyy-mm-dd hh:mm')",FALSE);
$this->db->set('AC_END',"TO_DATE('2014-05-5 2:34' ,'yyyy-mm-dd hh:mm')",FALSE);
$this->db->insert('ACTIVITES');code here
With that last parameter you are telling CodeIgniter to NOT escape this value.
Sonaryr's answer threw an Oracle error for me: ORA-01810
Oracle SQL Developer Statement Output:
Error report:
SQL Error: ORA-01810: format code appears twice
01810. 00000 - "format code appears twice"
*Cause:
*Action:
To Fix Change MM to MI:
$this->db->set('AC_START',"TO_DATE('2015-09-02 16:35' ,'YYYY-MM-DD HH24:MI')",FALSE);
Write Normal Query To Perform Action Against The TO_DATE(); Codegniter Does not have any library functions for to_date() for oracle.

Categories