Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem in codeIgniter library does not return a value
    primarykey
    data
    text
    <p>I have the following library in codeIgniter that has functions <code>getDbs()</code> and <code>getTables()</code> in the</p> <pre><code>return $dbs; </code></pre> <p>and</p> <pre><code>return tables; </code></pre> <p>the problem is they don’t return anything what am i doing wrong. Is it because i am using an array or sth</p> <pre><code>class Db_models { private $host; private $user; private $password; private $link; private $dbname; private $fields; public $dbs; //TODO make this flexible especially connect statement public function __construct($config) { $this-&gt;host = $config[0]; $this-&gt;user = $config[1]; $this-&gt;password = $config[2]; $this-&gt;link = mysql_connect($this-&gt;host, $this-&gt;user, $this-&gt;password); print_r($this-&gt;link); } //Get Databases function getDbs() { $db_list = mysql_list_dbs($this-&gt;link); $row = mysql_fetch_object($db_list); var_dump($row); while ($row = mysql_fetch_object($db_list)) { $dbs[] = $row-&gt;Database; } return $dbs; } //Get Tables function getTables($dbname) { $this-&gt;dbname = $dbname; $sql = "SHOW TABLES FROM $dbname"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } return $tables; } //Get Fields function generateFields($dbname,$table){ mysql_select_db($dbname, $this-&gt;link); $result = mysql_query("SHOW COLUMNS FROM $table"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } if (mysql_num_rows($result) &gt; 0) { while ($row = mysql_fetch_assoc($result)) { $this-&gt;fields[]=$row; } return $this-&gt;fields; } } } ?&gt; </code></pre> <p>Here is my cotroller</p> <pre><code>&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/&lt;method_name&gt; * @see http://codeigniter.com/user_guide/general/urls.html * */ private $fields=array('s'=&gt;'s'); public function __construct() { parent::__construct(); $this-&gt;load-&gt;library('db_models', $config = array('localhost', 'madawar_Madawar', '23goodboys')); } public function index() { // $this-&gt;load-&gt;library('db_models', $config = array('localhost', 'Madawar', '23goodboys')); $data['dbs'] = $this-&gt;db_models-&gt;getDbs(); $this-&gt;load-&gt;view('welcome_message', $data); } public function database() { $db_name = $this-&gt;input-&gt;post('database'); $data['db_name'] = $db_name; // $this-&gt;load-&gt;library('db_models', $config = array('localhost', 'Madawar', '23goodboys')); $data['tables'] = $this-&gt;db_models-&gt;getTables($db_name); $this-&gt;load-&gt;view('database_dash', $data); } public function generate($dbname,$table) { /*$data = decode(TRUE); print_r($data); echo "sd";*/ // $this-&gt;load-&gt;library('db_models', $config = array('localhost', 'Madawar', '23goodboys')); $data = $this-&gt;fields= $this-&gt;db_models-&gt;generateFields($dbname,$table); //print_r($data); $data=encode($data); echo $data; } public function getFields($some,$data) { echo $some; echo $data; // $this-&gt;load-&gt;library('db_models', $config = array('localhost', 'Madawar', '23goodboys')); $this-&gt;fields= $this-&gt;db_models-&gt;getFields(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload