Welcome Guest, Not a member yet? Register   Sign In
Newbie to CI - Problem connecting to mysql DB (blank pages rendered)
#1

[eluser]bhakti.thakkar[/eluser]
Code in database.php

Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "username";
$db['default']['password'] = "pwd";
$db['default']['database'] = "MyDB";
$db['default']['dbdriver'] = "mysqli";
$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";

Code in blog_model.php (Modal code)
Code:
<?
    class Blog_model extends Model {

    var $title   = '';
    var $content = '';
    var $date    = '';

    function Blog_model()
    {
        // Call the Model constructor
        parent::Model();
        $this->load->database();


    }
    
    function get_last_ten_entries()
    {
        $query = $this->db->get('Country_T', 10);
        return $query->result();
    }
}
?>


Code in blogview.php (View code)

Code:
<?
$Arr = array("Red" , "Green", "Blue");

?>
<html>
<head>
<title>My Blog</title>
</head>
<body>
    My Name is <?=$MyName?>
    <h1>&lt;?=$heading?&gt;<br>&lt;?=$title?&gt;</h1>
    &lt;?foreach($myarr as $key) print $key."<br>"; ?&gt;

    &lt;?foreach($Arr as $k) print $k."<br>"; ?&gt;


<p>Row count = &lt;?=$numrows?&gt;</p>


&lt;/body&gt;
&lt;/html&gt;
Code in blog.php (Controller file)
Code:
&lt;?php

class Blog extends Controller {
    function Welcome()
    {
        parent::Controller();    

    }
    
    function index()
    {
                
        $this->load->database();
        $this->load->model('Blog_model');


        $data['MyName'] = "Bhakti ";
        $data['title'] = "My Real Title";
        $data['heading'] = "My Real Heading";
        $data['numrows']=$this->Blog_model->get_last_ten_entries();

        $data['myarr'] = array("One" , "Two" , "Three" );

        $this->load->view('blogview', $data);

    }
} // end class

the problem is whem i try to connect to DB there are blank pages rendered
when i address it to :http://localhost/CodeIgniter/index.php/blog

blank pages are displayed. but when i remove the DB related things my plain PHP works fine

PLEASE HELP ME....

Thanks
#2

[eluser]bhakti.thakkar[/eluser]
At last i got it after a long long hours of search that it should be mysql instead of mysqli driver

Smile


$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "usename";
$db['default']['password'] = "pwd";
$db['default']['database'] = "MyDB";
$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";
#3

[eluser]manilodisan[/eluser]
was "mysqli" there by default?
#4

[eluser]bhakti.thakkar[/eluser]
no it wasn't there by default. But i use that driver for my other applications. dont know why it failed to connect.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB