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

EasyPHP 14.1 and PHP 5.3
How to do seamless integration (within the website) of PayU payment gateway in Magento?
How to get entire table data?
Creating zip file containing the files with UTF-8 encoding name in PHP using /usr/bin/zip
DOMDocument::load a lot of warnings
Cocos2d-x - How to upload file to server using PHP?
You have an error in your SQL syntax…?
only 20 images are uploaded
localhost project link not working
doctrine prevent from updating joined entity
Creating Navs for multiple directories
get_terms gives “invalid taxonomy” from plugin
PHP - multidimensional array to query string
Query mysql record and convert to array using php
Add PHP code before any other code in Wordpress template, on a per post basis
PHP execution time - prevent Apache from stopping script

Categories

HOME
barcode-scanner
qc
enums
hid
braintree
cypher
apache-kafka-connect
implicit-conversion
navigation
specifications
polymer-2.x
azure-logic-apps
clickable-image
nexus3
fullcalendar-scheduler
live-streaming
ex
django-rq
orange-api
vmware-workstation
coroutine
codefluent
scheduled-tasks
psql
pst
kaggle
amazon-sns
rxjs5
react-dnd
fusetools
plyr
bonita
boolean-logic
ibm-connections
tilemill
d3.js-v4
mongodb-3.4
fotorama
rspec-rails
cucumber-junit
overwrite
export-to-pdf
plane
newtons-method
ejml
word-cloud
yoast
wysihtml5
cyanogenmod
photoswipe
brightscript
uiautomatorviewer
sharpdx
entropy
palindrome
glimpse
polymaps
front-camera
google-shopping-api
annotatorjs
scheduledexecutorservice
google-identity-toolkit
okio
svnserve
django-testing
android-4.2-jelly-bean
ajaxmin
maximize
mathnet
jeditable
mercurial-extension
gdl
perceptron
decidable
nette
nastran
ambiguity
search-form
domino-designer-eclipse
tree-structure
text-align
findersync
cakephp-2.2
adwords-apiv201402
igor
full-text-indexing
otl
nodeload
jack
cloo
colon
codahale-metrics
node.js-stream
sunstudio
jquery-lazyload
flv
eager-loading
session-0-isolation
cyrillic
icenium
smartfox
viewpagerindicator
server-name
platform-independent
litespeed
glassfish-esb
snackjs
mongrel2
multiple-users
ccnet-config
pinax
mysqli-multi-query
firephp
accumulator
version-control-migration
rendering-engine
service-factory
jvm-bytecode

Resources

Encrypt Message