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

subdomain to url redirect with mod_rewrite and htaccess?
associate cakephp model to non-cakephp database table
Adding Content-type to Pear Mail
Form Evaluation With PHP
Loading an array of arrays from mysql
Parsing text in php
jquery- how to run ajax in document ready?
PHP: Building array out of values of another, associative, multidimensional array
Mobile Optimized site
Joomla 1.5.24: Why does the user gets logged out?
Applying PHP script to a file with multiple lines
replace text on your page php something like element.innerhtml
SessionHandler issue
Wordpress Conditional Sidebar Section Based off of Page ID
PHP Gettext - No translation
Uploadify calling CodeIgniter controller multiple times

Categories

HOME
office365
ionic2
events
yii
paypal-ipn
scroll
operating-system
plaid
openlayers-3
vsts-build
swift2
mosquitto
google-search-console
supercollider
firebase-database
wagtail
graphql-js
kurento
jpa-criteria
azure-logic-apps
amazon-emr
business-intelligence
stimulsoft
webstore
distributed-computing
heap-dump
robolectric
codefluent
psql
raml
data-type-conversion
coreldraw
multi-upload
fluent-migrator
pyopencl
react-dnd
environment
cellular-network
python-imageio
rust-cargo
xcrun
polyml
cups
netstat
jade4j
android-alarms
praat
oracle-bmcs
libreoffice-writer
sequence-diagram
mobile-angular-ui
sesame
gmaps.js
dymola
wildfly-9
d3v4
bpms
pbx
multi-touch
openquery
oci
node.js-connect
accessibilityservice
wepay
enunciate
m4
phpquery
google-maps-api-2
astropy
dnx50
wlanapi
wicked-gem
kotlin-android-extensions
fiware-bosun
fat32
juttle
relationships
hyperloglog
sqlbindparameter
jchartfx
strcmp
vlab
insertonsubmit
insertion
red-system
ckeditor.net
xalan
cgrectmake
towers-of-hanoi
arrow
viewpagerindicator
gamesalad
algol68
differentiation
qtextbrowser
delphi-prism
simile
grails-validation
nsconnection
3des
active-record-query
multiple-users
activestate
icicles

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