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

Redirect login page when user already logged
Save data to join table in CakePHP 3
How to limit the records in the right inner join table in Yii framework 2?
Detect current language direction with SilverStripe translatable module
Display validation error in tabs using laravel
Change the laravel hasing mechanism to encrypt and store the password in users table
Check if the whole row exists
Laravel change default primary key of users table
ListView component filters: the data from MySQL using queries or from the class using functions?
Only variables should be passed by reference php
Referring to a Column Alias in a HAVING Clause with variable
PHP, Slim, twig templates, can't use PHP in main template?
create breadcrumbs by self-referencing table
mPDF background image speed problems
PHP Check if mysql database contains string in string
Logic for parsing XML file with different tag names within the same hirearchy using PHP

Categories

HOME
elasticsearch
kendo-dropdown
concurrency
antd
tcsh
dry
odata
nsis
google-sheets-query
turbojpeg
tweepy
gtk
solution
nexus3
graphdb
pm2
grocery-crud
multi-step
freertos
sql-injection
mahout-recommender
synthesis
rest-assured
uima
renderscript
bazaar
tableview
workday
bosun
multi-upload
eclipse-emf
chronicle-queue
environment
jackrabbit-oak
ccavenue
adapter
intune
xenapp
premake
mongoengine
counting
nest
cloveretl
jfxtras
wdk
textmate2
bluemixtools
love2d
ms-solver-foundation
twilio-php
eclipse-gmf
gitolite
flipkart
optionaldataexception
jshint
sonarqube5.2
return-type
ol3-google-maps
punctuation
android-sharing
dtd
pecl
dymola
kendo-treeview
http4s
gawk
petsc
metabase
jsf-2.3
django-testing
groovyfx
apache-pig-grunt
odp.net-managed
urbit
xcopy
google-maps-api-2
ora-04091
knife
bootstrap-wysiwyg
textscan
abstract-factory
clarion
nsmutabledata
mutators
htmltidy
mojo
uno
comctl32
adhoc-polymorphism
smacss
redpitaya
neo4jphp
incognito-mode
reference-counting
refit
zend-search-lucene
preorder
oxygene
django-sites
revmob
iirf
dynamic-rdlc-generation
arel
ofstream
smartfox
email-verification
jquery-dialog
daap
image-formats
coordinate
jdom
jmenu
pyjamas
icicles
aspbutton
zend-test
mysqli-multi-query
watchpoint
error-detection

Resources

Encrypt Message