Welcome Guest, Not a member yet? Register   Sign In
Call Procedure in CodeIgniter
#1

[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.
#2

[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?
#3

[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
#4

[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
#5

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

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

[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!....




Theme © iAndrew 2016 - Forum software by © MyBB