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

Sending a request to a php web service from iOS
Show an image from an ubuntu server
how to save canvas for gradient background php/html5?
Merging Excel cells does not work PHPExcel
How to remove word says: from comments of wordpress latest 4.4 version
Stacked objects, bad practice?
How to make my extension support opcache in php?
List catagories order by Random
How to run a cron job on a CodeIgniter controller that all the URL does is run a query from an API, update the DB & send emails (from within CI)?
Is it possible to wrap the whole website in an iframe?
Does scope change at all when including class files in a class method in PHP?
why is it that info.php only work if placed in /var/www/html not /var/www/?
Create WHERE with array in PHP
jQuery not working on url click
ACF flexible content - image doesn't show
How to correctly parse this text with PHP? I'm halfway there [duplicate]

Categories

HOME
google-chrome
elasticsearch
lambda
android-fragments
odata
typeerror
mathematical-optimization
tibco
azure-mobile-services
log4j2
jpa-2.0
mahout-recommender
texas-instruments
google-sites
home
sqlplus
maven-surefire-plugin
perfino
dragula
raima
hdmi
android-cardview
macromedia
ninject
envoy
credit-card
xenapp
toad
directfb
transform
wdk
cargo
strapi
django-smart-selects
hidden-markov-models
vb.net-to-c#
cloudera-sentry
dagger
elasticsearch-aggregation
httphandler
sendinput
audio-converter
liteide
lightning-workbench
gtk#
business-rules
google-shopping-api
maatwebsite-excel
always-on-top
coovachilli
fdt
swiffy
management-studio-express
chicagoboss
canopy
ngcordova
scala-swing
python-curses
debug-symbols
thoughtworks-go
iplimage
quantify
webautomation
zend-search-lucene
mod-perl
jquery-transit
dibs
days
ntlmv2
playorm
word-frequency
telerik-ajax
firebird1.5
quartz-core
vows
azure-acs
mongrel2
eaccelerator
solandra
tabbarcontroller
server-load
html-generation

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App