Ocassional error number 0 executing query in CodeIgniter - php

I am developing an application with code igniter and sometimes I got this error when I am calling a view that is loading data from the dabase:
Error Number: 0
SELECT `medidas_ludlum_5min`.* FROM (`medidas_ludlum_5min`) WHERE (FK_ludlum="190.26.88.131" and measurement >= "0.0" and fecha between "2014/04/01 11:49:03" and "2014/05/27 11:49:03")
Filename: C:\xampp-win32-1.7.5-VC9\xampp\htdocs\dashboard\system\database\DB_driver.php
Line Number: 330
Can some one help me to figure it out what is related to error 0? Or what can be happening?
Thanks.

You might want to look at the simple_query function. It seems that the usual query function has a mysql diver bug: http://ellislab.com/forums/viewthread/181751/#860516
If it returns false there might be something else wrong with the query.
Maybe an uneacaped value

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.

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.

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

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

Categories