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

Display images from WordPress post
Zend framework 1 - Can't get through login page
A2Billing subscription change
Mailwatch Quarantine Not Showing Contents
Too Many Redirect Error with htaccess for site
Apache 2 + PHP - Issue with .htaccess permissions
How to output database data as separate integers in order to use them for an if-else condition?
Magento - Get Configurable Product Available Sizes
Eloquent - Eager Loading Relationship
Cannot verify a saved a temporary password in php used in android
php get function argument length
All the data are not retrieved from a field in mysql
Open socket and send packets in PHP through SOCKS5
How to move blob from one table to another? [duplicate]
One to one combine array values
Php, how to remove characters after asterisk and stop at file extension

Categories

HOME
elasticsearch
xpath
android-espresso
powerbi
seedstack
message-queue
risk-management
android-emulator
openflow
amp
iptables
openfoam
haxe
scheduler
tfs2010
anchor
yahoo
bundler
orange-api
nest-api
closures
rpmbuild
google-sites
gmp
nose
social-tables
bosun
altium-designer
quantitative-finance
cell
backendless
pyopencl
strophe.js
running-object-table
macromedia
boolean-logic
splunk-query
d3.js-v4
xenapp
devtools
winrm
custom-keyboard
android-alarms
hidden-markov-models
vb.net-to-c#
distributed-caching
flipkart
vungle-ads
elasticsearch-aggregation
docker-ucp
destroy
gcal
cloudwatch
clrs
email-forwarding
cognos-tm1
qtextedit
mifos
elastic4s
bigdecimal
system.web.optimization
gcloud-node
callouts
raw-sockets
between
accessibilityservice
gwt-syncproxy
vimperator
okta-api
univocity
management-studio-express
wikimedia-commons
gdl
blank-line
sqlbase
enaml
hmisc
supercomputers
swagger-maven-plugin
karma-coverage
erlog
physicsjs
subfolder
signed
mutators
juttle
flurry-analytics
angular-ui-select
forceclose
jms-serializer
armv6
ctp
eclim
apache-shindig
jacob
spiral
arel
asp.net-mvc-3-areas
dojo-1.9
tridion-2011
multiple-dispatch
android-dialog
word-frequency
taskkill
opends
kolite
memory-pool
delphi-prism
kernel32
simile
mongrel2
eaccelerator
uninstaller
reliability
fgetc
.net-services
eai
tso

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App