Welcome Guest, Not a member yet? Register   Sign In
MYSQL problem
#1

[eluser]Speedy`[/eluser]
Hi there,

I have one little problem here.

I am trying to use database functions from codeigniter but it seems there is a problem with the functions or my code.

I have this

$this->db->where('date',$data['date']);
$query = $this->db->get('exchangerates');

with $this->db->last_query() it generates this
SELECT * FROM (`exchangerates`) WHERE `date` = '2012-11-21'

the $query->num_rows() returns 0 even if in the database are records with this date.

same problem at insert.
$exchange = array(
'date' => $data['date'],
'usd' => $data['usd'],
'eur' => $data['eur']
);
$this->db->insert('exchangerates',$exchange);

echo $this->db->last_query(); generates this
INSERT INTO `exchangerates` (`date`, `usd`, `eur`) VALUES ('2012-11-21', '3.5474', '4.5339')

When I run this sql from phpmyadmin it is all OK. From codeigniter the date is inserted as '0000-00-00'

Can anyone tell me how to solve this problem? I have tried to convert string to date from human to unix, to call date() but nothing happened.

Thanks
#2

[eluser]jprateragg[/eluser]
What version of CI are you using?
#3

[eluser]InsiteFX[/eluser]
Try:
Code:
1)
var_dump($data);
exit;

$date = $data['date'];
$this->db->where('date =', $date);

2)
$date = $data['date'];
$usd  = $data['usd'];
$eur  = $data['eur'];

$exchange = array(
    'data' => $data,
    'usd'  => $usd,
    'eur'  => $eur
);

If that doe's not work try using this:
Code:
$this->db->where('date =', $this->data['date']);
#4

[eluser]Speedy`[/eluser]
[quote author="jprateragg" date="1353547507"]What version of CI are you using?[/quote]

2.1.3

I-ll try the methods and come back withan answer

#5

[eluser]Speedy`[/eluser]
[quote author="InsiteFX" date="1353550555"]Try:
Code:
1)
var_dump($data);
exit;

$date = $data['date'];
$this->db->where('date =', $date);

2)
$date = $data['date'];
$usd  = $data['usd'];
$eur  = $data['eur'];

$exchange = array(
    'data' => $data,
    'usd'  => $usd,
    'eur'  => $eur
);

If that doe's not work try using this:
Code:
$this->db->where('date =', $this->data['date']);
[/quote]

It seems that is not working

Undefined property: Site::$2012-11-21

The sql returns 0 rows from codeigniter and phpmyadmin returns 1. Sad
#6

[eluser]JunlieF[/eluser]

pls. corrent me about this code...

$sql = "SELECT * FROM deparments, prints WHERE 'id{$dept}' AND 'date_printed BETWEEN '{$from}' AND '{$to}'";
#7

[eluser]Speedy`[/eluser]
[quote author="JunlieF" date="1353582092"]
pls. corrent me about this code...

$sql = "SELECT * FROM deparments, prints WHERE 'id{$dept}' AND 'date_printed BETWEEN '{$from}' AND '{$to}'";[/quote]

Where clause
WHERE column_name operator value

I'm seing just the value not the column.

Operators can be =.!=, <, >....
#8

[eluser]Speedy`[/eluser]
nobody knows where the problem with the date is?
#9

[eluser]kostyak[/eluser]
Hi Speedy!
Try to use different date format from which you have being used.
I think that it would be better to use standart month/date/year format instead of year-month-day.

Also I had situation with mssql database. When I use smaldatetime - I received the same problem. When I swichen to datetime - all is ok.

Try it. It seems that problem not in CI, which you use.




Theme © iAndrew 2016 - Forum software by © MyBB