Welcome Guest, Not a member yet? Register   Sign In
Database doesn't work on server but works locally
#1

[eluser]mojitoo[/eluser]
Hey!

I need som help. This code works perfect when I execute it locally but it doesn't work when I upload it to a server.
You're able to see that I've added some code to the database that tells me that the connection is OK!

database.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');


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

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$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;

/* echo '<pre>';
     print_r($db['default']);
  echo '</pre>';

  echo 'Trying to connect to database: ' .$db['default']['database'];
  $dbh=mysql_connect
  (
    $db['default']['hostname'],
    $db['default']['username'],
    $db['default']['password'])
    or die('Cannot connect to the database because: ' . mysql_error());
    mysql_select_db ($db['default']['database']);

    echo '<br />   Connected OK:'  ;
    die( 'file: ' .__FILE__ . '--&gt; Line: ' .__LINE__); */


/* End of file database.php */
/* Location: ./application/config/database.php */

controller, site.php
Code:
&lt;?php

class Site extends CI_Controller {

function index()
{
  $data = array();

  if($query = $this->site_model->get_records())
  {
   $data['records'] = $query;
  }

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

model, site_model.php
Code:
&lt;?php

class Site_model extends CI_Model {

function get_records()
{
  // data = table name in db
  $query = $this->db->get('data');

  var_dump($query);

  return $query->result();
}
}

You're able to see a var_dump in my model that returns bool(false)
I also get this error:
Fatal error: Call to a member function result() on a non-object in /home/site/public_html/test/application/models/site_model.php on line 12

Please try to help me with this, it's really frustrating since it works locally.


Messages In This Thread
Database doesn't work on server but works locally - by El Forum - 04-01-2012, 03:48 AM
Database doesn't work on server but works locally - by El Forum - 04-01-2012, 05:02 AM
Database doesn't work on server but works locally - by El Forum - 04-01-2012, 05:43 AM
Database doesn't work on server but works locally - by El Forum - 04-01-2012, 07:49 AM
Database doesn't work on server but works locally - by El Forum - 04-01-2012, 07:54 AM
Database doesn't work on server but works locally - by El Forum - 04-01-2012, 08:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB