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

Total result for PHP
How to use Endroid\QrCode on Yii2?
How to validate an angularjs in textbox?
Laravel website upload on cPanel error
LDAP Authentication not working for login page
Relational database with multiple preferences and categories
I can not create PHP array from JSON [closed]
PHP Amqp channel callback loop
Symfony2: How to add a form created using factory builder into another form's collection type field?
http request failed to open stream on php file_get_content
Vagrant multi-machine - connection between machines
silex custom/persistant remember me
Remove file name “specification.php?url=” from url
Solve New Line in JSON via PHP
Slash or Space in sphinxql in a faucet field does not work
Codeigniter can't load big custom library

Categories

HOME
google-chrome
elasticsearch
spring-data
vagrant
opencv-python
kendo-dropdown
workflow
hid
loopbackjs
odata
docker-cloud
nsis
greasemonkey
javafx-8
wagtail
pyresttest
colors
watch-os-3
async-await
reselect
pinterest
infrared
generator
web-push
sendmessage
unmarshalling
guice
matlab-app-designer
mapnik
argv
transform
xerces-c
wdk
swfupload
dagger
.net-micro-framework
hibernate-ogm
word-2016
zend-server
finder
okio
xcode8-beta4
powerpoint-2013
android-syncadapter
gridbaglayout
android-expansion-files
flush
voronoi
roxygen2
unidata
tree-structure
fuseesb
shell-extensions
signed
python-c-extension
incron
mod-auth-openidc
directorysearcher
nidaqmx
aho-corasick
maven-central
network-printers
refit
spring-social-linkedin
hyphen
mp4parser
insertion
dynamic-rdlc-generation
android-authenticator
jquery-cycle
semantic-merge
xalan
daap
spark-view-engine
gitx
uploading
asio
boost-foreach
jquery-1.4
css-friendly
3des
iphone-sdk-4.3
wmd-editor
main-method
eai
downcasting
sqlsitemapprovider
rakudo
stretchblt
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