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

Custom Super Global variable name in hhvm
$.get can't pass the data to the php file
posting to google plus through api
PHP - Replace all text after two specific characters
SQL/PHP: Show top 3 most sold/viewed products images from database in slider of website
Codeigniter mysql db query to display 3 rows of results on page using 2 tables on 3 joins
Parse error: syntax error, unexpected end of file in php. Couldn't find where did i do wrong? [duplicate]
Dropzone.js post request in laravel 5.4
Error trying to fetch data from 2 tables codeigniter
Split Up String With Two Conditions: “+” and “-” And Keep Signs
Laravel issue on migration
PHP logging out by using class
Why in PHP7.1 2 level of break has been removed and what could be its alternate solution?
How simplify PHP function with array key-values?
Php if Else in form action
Create an account to manipulate database in PHP

Categories

HOME
libgdx
angular-ui-grid
focus
windows-10
devexpress
plpgsql
braintree
odata
magento-2.0
informatica
consul
firebase-dynamic-links
log4j2
yahoo
match
lapack
cname
smooks
complexity-theory
dma
google-tasks-api
android-5.1.1-lollipop
susy-sass
raml
azure-machine-learning
el
conda
batch-rename
restier
pdf.js
mod-wsgi
math.js
dnsmasq
wampsharp
netstat
eclipse-gmf
flowchart
icepdf
ejml
1wire
elasticsearch-aggregation
httphandler
docker-ucp
xcode8.2
kitura
photoswipe
sonicmq
http-basic-authentication
rcharts
word-2016
ipywidgets
bigdecimal
xcode6.4
callouts
fiber
powerpoint-2013
android-syncadapter
chicagoboss
jnlp
apple
bootstrap-wysiwyg
ipod
webproject
innerhtml
android-audiomanager
iodocs
webmethod
coding-efficiency
senchatouch-2.4
redpitaya
roxy-fileman
grails-2.3
san
microformats
sunstudio
statechart
flv
tfs-sdk
story
fitch-proofs
mmc3
servercontrol
turbine
ninject-interception
spring-modules
powergui
icon-language
suggestbox
parentid

Resources

Encrypt Message