php


Error connecting DB with Codeigniter


I have seen the same problem a hundred times here. But for some reason, all those solutions don't work for me. I'm using Ajax to connect to the database through the controller and model. But the Ajax request returns error every time. I think the problem may be located in the database.php.
Ajax:
$.ajax({
type: "POST",
url: '<?php echo site_url("Main/resultadosBusqueda")?>',
success: function(result){
alert('Success:'+result);
},
error: function(result){
console.log( JSON.stringify(result, null, 2) );
alert('Error:'+result);
}
});
Controller:
public function resultadosBusqueda() {
$this->load->model('Buscar_model');
echo $this->Buscar_model->buscarCartas();
}
Model:
class Buscar_model extends CI_Model {
public function __construct() {
parent::__construct();
}
public function buscarCartas() {
$this->db->select('Card');
$this->db-> from('Cards');
$query = $this->db->get();
return $query -> result_array();
}
}
database.php
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'CardTrade',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Add the following to the .ajax options after url: ...
dataType: 'json',
Then in the controller the last line should be
echo json_encode($this->Buscar_model->buscarCartas());
May not be exactly what you expect but it might cure the error everytime problem.

Related Links

PDO Fetch IMSSP Invalid Type
Array to string conversion error in FOR LOOP using CI
check which option value is selected from <select> tag
mysql php: How to bind result with the same recurring variable [duplicate]
Parse error: syntax error, unexpected '*' [duplicate]
How to display 2nd last record using mysql query?
user account report in php mysql like bank passbook [closed]
sending mail using post method [duplicate]
File permissions on uploads directory in PHP
PHP insert index as value in array
PGP GD page source code shown instead of image
mysql to postgresql database error
shell_exec() issue, certain hosts disable this by default, looking for a walk around
PHP writing comments on the code [duplicate]
Take user from one page to the other with a value [duplicate]
PHP Get query results doesn't work

Categories

HOME
libgdx
functional-programming
d3.js
hid
plaid
wagtail
fbloginview
mailmerge
sql-injection
temperature
pinterest
codefluent
nullreferenceexception
connection-refused
backendless
quartz.net
tortoisemerge
fstar
python-imageio
social-networking
locks
vcenter
nest
gitolite
resampling
classnotfoundexception
opal-framework
access-denied
reverse-dns
kitura
rm
lightning-workbench
cordova-ios
embedded-v8
sesame
researchkit
multi-touch
mathjs
system.web.optimization
seccomp
spring-mongo
eclemma
wicked-pdf
odp.net-managed
cortana
variable-length-array
html.actionlink
decidable
dnx50
algebraixlib
quercus
ssmtp
fiware-bosun
juttle
global-scope
windows-rt
jquery-mobile-flipswitch
xcode6.3.1
incognito-mode
meteor-collections
django-settings
mft
boinc
dynamic-rdlc-generation
icenium
ckeditor.net
simplecov
delphi-prism
getopts
nsrangeexception
azure-acs
ognl
turbine
jdownloader
ccnet-config
subtext
rakudo
regioninfo

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile