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

How do I parse these strings?
SQLite3 duplicates
Socket read timeout on ajax request: any workaround?
Get Current Time With given Timezone offset
can't include the .php file properly
file upload with cakephp maldicore admin plugin
PHP/JavaScript YouTube To MP3 Converter [closed]
How to inject javascript code that uses php variables into php page
Unrecognized options swift_mailer under sonata_notification.consumers error
PHP file_get_contents different behaviour for the same domain
Why does asort work with multidimensional arrays?
How to insert array of custom objects into mysql database
Problems extracting a .tgz with PHP
insert image with session
How to create a subdomain using htaccess
When to use the Increment Operator on Strings in PHP? [closed]

Categories

HOME
powerbi
blast
angular-ui-grid
yii
xcode8.1
paypal-ipn
postgresql-9.4
activex
operating-system
out-of-memory
qooxdoo
google-sheets-query
flurry
ontology
joomla3.2
u-boot
angular2-template
eddystone
gtk
siesta
lda
xamarin-zebble
lapack
stimulsoft
twisted
pygobject
jqxgrid
cloudsim
clr
connection-refused
fluent-migrator
firemonkey-style
prompt
unrar
hevc
openbravo
pyspark-sql
mdns
mapnik
actframework
mongoengine
xmlunit
django-smart-selects
imgur
get-event-store
transparency
oracle-bmcs
libreoffice-writer
nonlinear-functions
node-apn
sigsegv
webvtt
gtk#
freshdesk
gnome-terminal
sidewaffle
finder
email-injection
scheduledexecutorservice
system.web.optimization
svnserve
xcode8-beta4
openseadragon
yii2-model
apache-pig-grunt
xcopy
verisign
ioctl
cryptojs
in-app-billing
place
nastran
shoes
kotlin-android-extensions
python-curses
debug-symbols
adhoc-polymorphism
configurable-product
cout
adwords-apiv201402
igor
mfmessagecomposeview
two.js
jmenubar
frontbase
stty
sunstudio
jbox2d
linkbutton
multiple-dispatch
zend-pdf
live-wallpaper
infopath-2007
delphi-prism
kohana-auth
fragment-identifier
3des
gaelyk
ios-4.2
explicit
uninstaller
odac
aspbutton
tso
rakudo
remote-working
html-generation
service-factory

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