Welcome Guest, Not a member yet? Register   Sign In
Active Record and SQL error
#1

[eluser]al404[/eluser]
i'm using Active Record Class to get data from a table
but something is going wrong, and i just get a general error

but i would need to see the SQL passed and /or the MySql error

how can i get it?
in db config file is
$db['default']['db_debug'] = TRUE;
#2

[eluser]PowerCode[/eluser]
You'll need to give more information. Specifically, the error that you get (even if it's general, since not everyone might know what it really is, like me Wink). Also, you'll need to post the code you're using, if you're sure it's causing the problem. Normally, a new installation of CI would automatically show the MySQL error if there really is a problem with the query syntax.
#3

[eluser]al404[/eluser]
i didn't post the error messag because it is traslate....

if i reset to english it is

A Database Error Occurred
The query you submitted is not valid.

the problm was caused by
$this->db->select_max(100);

i thoght that this was needed to add a LIMIT at the query
#4

[eluser]Michael Wales[/eluser]
The ActiveRecord documentation clearly states:

Quote:$this->db->select_max();
Writes a "SELECT MAX(field)" portion for your query. You can optionally include a second parameter to rename the resulting field.

Code:
$this->db->select_max('age');
$query = $this->db->get('members');
// Produces: SELECT MAX(age) as age FROM members

$this->db->select_max('age', 'member_age');
$query = $this->db->get('members');
// Produces: SELECT MAX(age) as member_age FROM members

Absolutely nothing concerning a LIMIT, nor does it expect you to pass an integer parameter (instead it needs a field, so it can select the maximum value for that field within the table).

On the other hand:
Quote:$this->db->limit();
Lets you limit the number of rows you would like returned by the query:

Code:
$this->db->limit(10);

// Produces: LIMIT 10

The second parameter lets you set a result offset.

Code:
$this->db->limit(10, 20);

// Produces: LIMIT 20, 10 (in MySQL. Other databases have slightly different syntax)

I'm really not trying to be cynical here and this is rare of me but come on people... at least try.
#5

[eluser]al404[/eluser]
i found my error but the point is that i didn't get an output of the query (sql genereted) or of mysql like "you have an error near..."
this way is very hard to find where is the error, i try adding comments before different peace of code
#6

[eluser]aruna[/eluser]
hi,
i m having the following error .The error is because of the usage of the operator >= in the query
$this->db->where("sn.version_ts>=",recentdate);
will anyone solve it please.....


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 ''1999-04-27' GROUP BY `sn`.`id` ORDER BY `sn`.`version_ts` DESC LIMIT 50' at line 4

SELECT `sn`.`id`, `sn`.`title`, `ln`.`id` as lid, `ln`.`name` as lname, `ln`.`slug` as lslug FROM (`snippet` as sn) JOIN `language` as ln ON `sn`.`language_id`=`ln`.`id` WHERE `sn`.`version_ts>=` '1999-04-27' GROUP BY `sn`.`id` ORDER BY `sn`.`version_ts` DESC LIMIT 50
#7

[eluser]Armchair Samurai[/eluser]
Put a space between your column and your operation.

Code:
$this->db->where(“sn.version_ts >=”,recentdate);
#8

[eluser]aruna[/eluser]
[quote author="Armchair Samurai" date="1236249570"]Put a space between your column and your operation.

Code:
$this->db->where(“sn.version_ts >=”,recentdate);
[/quote]


ya ..Now i got it....Now its working...
But i m getting some other error...

Parse error: syntax error, unexpected T_STRING in
/home/ntdg/public_html/codeigniter/system/plugins/dompdf/include/dompdf.cls.php(277) : eval()'d code on line 692


The code works well for other cases..but when i clicked the month april i m getting this error..
following s the controller..to_pdf_file($month)...when i selected a month from my interface(views)



function to_pdf_file($month)
{
$snippet["codedetails"]=$this->Admin_Model->get_all_code_bymonth($month);
$snippet["month"]=$month;

$html=$this->load->view("view_pdf",$snippet,true);
pdf_create($html,'Month',TRUE);
}

the following in my views(view_pdf)
&lt;? if($codedetails){ ?&gt;<ol>
&lt;? ?&gt;

<table border="1" width="200">
<tr><th>ID</th><th>TITLE</th><th>DESCRIPTION</th><th>CODE</th><th>VERSION</th></tr>
&lt;?foreach($codedetails as $s=>$ss){?&gt;


<tr>
<td> &lt;?=$ss['id'];?&gt; </td>
<td> &lt;?=$ss['title'];?&gt; </td>
<td > &lt;?=$ss['description'];?&gt; </td>
<td> &lt;?=$ss['code'];?&gt; </td>
<td> &lt;?=$ss['version_ts'];?&gt; </td>

</tr>

&lt;?}?&gt;
</table>

&lt;?
}else{?&gt;
<p>list is empty</p>
&lt;? }

?&gt;


its not working for the month march.........please anyone resolve it.........


when i selected the month april , i m getting the error as


Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 39 bytes) in /home/ntdg/public_html/codeigniter/system/plugins/dompdf/lib/class.pdf.php on line 2373


please anyone resolve this too.....
#9

[eluser]richie123[/eluser]
hi all
I got a prolem, in my model, I select a limited record set as following line


Code:
if(!is_null($offset))
   $this->db->limit(1, $offset);            
$query = $this->db->get('user');


in this case, my $offset = 0, and the output query is generated like this

Code:
SELECT * FROM (`user`) LIMIT 1

instead of

Code:
SELECT * FROM (`user`) LIMIT 0, 1

so the question is : where is my $offset variable? is there some thing wrong with my code or it a bug of CI???
#10

[eluser]nzmike[/eluser]
Having no offset and an offset of 0 and are the same thing aren't they?




Theme © iAndrew 2016 - Forum software by © MyBB