CodeIgniter Forums
Call Procedure in CodeIgniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Call Procedure in CodeIgniter (/showthread.php?tid=42723)



Call Procedure in CodeIgniter - El Forum - 06-17-2011

[eluser]super_Tai[/eluser]
I'm newbie in CodeIgniter. I used MySQL.
Can you show me the way to call procedure in CodeIginter.
I searched Google. The result was:

$query = $this->db->query("call helloworld() as A")
$query->result();
echo result->A;


but it did'nt work well.
It had an error: Unable to specified database:blog
Although in database.php file I configed as follow:

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'blog';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

Note:
helloworld() is my procedure with the command: "SELECT * FROM data".

Help me! Thanks.
If you can give me an example is the best way to help me understand.


Call Procedure in CodeIgniter - El Forum - 06-17-2011

[eluser]marjune[/eluser]
before calling your procedure just try this first
Code:
$query = $this->db->query(“SELECT * FROM data”)
$query->result();
echo result->fieldname;

then whats the result?


Call Procedure in CodeIgniter - El Forum - 06-17-2011

[eluser]super_Tai[/eluser]
[quote author="marjune" date="1308324818"]before calling your procedure just try this first
Code:
$query = $this->db->query(“SELECT * FROM data”)
$query->result();
echo result->fieldname;

then whats the result?[/quote]


I tried this, it worked well but when I call store procedure it had an error:


" Unable to select the specified database: blog

Filename: C:\xampp\htdocs\CodeIgniter\system\database\DB_driver.php

Line Number: 140 "

although i don't change anything from file DB_driver.php


Call Procedure in CodeIgniter - El Forum - 06-17-2011

[eluser]InsiteFX[/eluser]
Did you setup database.php and then load the database?
Code:
$query = $this->db->query("call storedFunction($param1, $param2) as WhatEver");
$row = $query->row();
echo $row->WhatEver;

InsiteFX


Call Procedure in CodeIgniter - El Forum - 06-17-2011

[eluser]marjune[/eluser]
it pretty much obvious that your error is about calling your procedure!!


Call Procedure in CodeIgniter - El Forum - 06-17-2011

[eluser]InsiteFX[/eluser]
He's not passing the parameters to it!


Call Procedure in CodeIgniter - El Forum - 06-17-2011

[eluser]super_Tai[/eluser]
Smile I tried to call my procedure. It is surprised that in the first time I call procedure. It works well but when I refresh my page. It appeared the error I mentioned above... Smile...
thanks for your idea!....