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

Mysql create a table out of some data
date/gmdate returns wrong week number
How do I Spread out an array with possible empty slots?
MySQL calcualge difference in select query
How to embed a whole project into a phar file?
can i add a new page in wordpress as like add link html [closed]
XAMPP Server using Multiple ports instead port 80
Reseller club price detecting API
php file without “?>” [duplicate]
SELECT LAST_INSERT_ID() not generating correctly
Converting MYSQL connection to PDO [duplicate]
Create JSON with PHP (multilevel)
Why isn't my Controller working but throwing a FileLoaderException?
How can I stop third party applications from accessing server side data through requests?
how to get value of Multiple text inputs with same name
How do I configure $this->cwd for symfony2 framework

Categories

HOME
mc
yii
seedstack
writefile
plpgsql
ant
out-of-memory
twitter-fabric
header
flurry
implicit-conversion
javafx-8
u-boot
azure-logic-apps
siesta
heuristics
mailmerge
feature-extraction
ex
heap-dump
bnf
web-deployment
asciimath
susy-sass
boomi
cloudsim
tfsbuild
web-push
fusetools
introspection
window-managers
strophe.js
ruby-daemons
python-imageio
npoi
miniprofiler
unmarshalling
nic
appcode
payeezy
custom-keyboard
autoencoder
wdk
pdfnet
nanogallery
hidden-markov-models
android-n
reset
swfupload
utf
angular-datatables
notesview
doctrine-extensions
directwrite
scala-breeze
knockout-2.0
non-linear-regression
maven-jaxb2-plugin
email-forwarding
pecl
deviare
pjax
raw-sockets
openseadragon
dpkg
node.js-connect
maximize
canopy
css-paged-media
org-babel
com0com
kotlin-android-extensions
quercus
nssortdescriptor
kognitio-wx2
uno
dos2unix
microsoft-expression-web
string.format
window-resize
multivariate-testing
libgcc
full-text-indexing
jchartfx
django-sites
application-blocks
saga
infinite
rautomation
notifyjs
libxml-js
notin
significant-digits
story
first-class
cakeyframeanimation
series-40
fitch-proofs
haiku
winsxs
tablet-pc
fragment-identifier
regression-testing
git-log
sscli
google-translator-toolkit
icon-language
account-management

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile