i'm using codeigniter on google appengine ,
my issue is that appengine is unable to run query on the cloud sql ,
the my app on the appengine is able to connect to the cloud sql,
i have same setting in my local host and it's able to connect and run query on cloud sql,
i tried to debug the query function in the codeigniter , and i confirmed that both my appengine and my application in my local host are using the same exact query :
SELECT *
FROM (`grs_user`)
WHERE `username` = 'Admin'
AND `password` = '*******'
AND `is_published` = 'True'
i confirmed this by printing out the $sql var in get_where() function inside DB_active_rec.php .
database.php :
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = null;
$db['default']['database'] = 'fsm';
$db['default']['dbdriver'] = 'mysql';
$db['default']['pconnect'] = TRUE;
$db['default']['dbprefix'] = 'grs_';
$db['default']['swap_pre'] = '#__';
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['autoinit'] = TRUE;
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['cachedir'] ='';
$db['default']['stricton'] = FALSE;
$db['default']['socket'] = '/cloudsql/fsmocs:asia-east1:fsm';
database name is correct ,
anyone had such issue ?
after using the first generation SQL it's working now ,
i used same setting and same DB .sql file .
Related
After login, I set session with user id and some information. It works very well on Google Chrome.
But it is redirect to login page after login on Firefox. I don't know what is the problem. Furthermore, the strange issue is this is working well on my local server like 127.0.0.4. This redirect issue is occurred on live server(hostinger) and only on Firefox.
Here is my config.php
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'eq_session';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = TRUE; // JFRH
$config['sess_table_name'] = 'eq_sessions'; // JFRH
// $config['sess_save_path'] = NULL;
$config['sess_save_path'] = FCPATH . 'public/sess';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_match_useragent'] = FALSE;
And this function is customized library for authentication.
public function sess_validate($redi = FALSE, $sess_upda = FALSE) {
$CI =& get_instance();
if ($CI->session->userdata('sess_id')) {
//Preguntar si la variable de sesiĆ³n 'usua' existe o si se requiere
//que los datos de la misma sean actualizados
if ((!$CI->session->userdata('usua')) || ($sess_upda == TRUE)) {
$this->__sess_update();
}
return TRUE;
} else {
if (!$redi) {
return FALSE;
} else {
print "<script> window.location.href = '". base_url('auth')."'; </script>";
}
}
}
I set session data in my Auth Controller like this.
$this->session->set_userdata('sess_id', $usua->id_usu);
$this->session->set_userdata('sess_na', $usua->nom_usu . " " . $usua->ape_usu);
$this->session->set_userdata('sess_log', $usua->log_usu);
I have tested with changed session path.
I have fixed this.
Here are my config.php.
$root = "http://".$_SERVER['HTTP_HOST'];
As you can see, I was set the root like above line.
It works on my local server but server protocol was https when I deploy this on server. It is a cause of this problem.
So I fixed this like this.
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === 0 ? 'https://' : 'http://';
$root = $protocol . $_SERVER["HTTP_HOST"];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
Now, works fine.
For some reason I can't get the database library to work. Any time I put the line $this->load->database(); the script stops executing without returning any errors.
This is my database.php:
$db['default']['hostname'] = '127.0.0.1';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'employee';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
This is my model:
class Customers_model extends CI_Model
{
function __construct()
{
parent::__construct();
//$this->load->database();
}
function add_customer($data)
{
echo "BEFORE CHECK";
$this->load->database();
echo "OK";
}
}
As I said, it doesn't return any errors. So in this case the screen will return "BEFORE CHECK" but it wont: "OK". Any ideas?
Try to change persistent connection $db['default']['pconnect'] = TRUE; to $db['default']['pconnect'] = FALSE; Or you can enable error log in config file from $config['log_threshold'] = 4; where Threshold options :
0 = Disables logging, Error logging TURNED OFF
1 = Error Messages (including PHP errors)
2 = Debug Messages
3 = Informational Messages
4 = All Messages
Make sure that you have 'error_reporting = E_ALL' in your php.ini to display any errors that occurs.
After that, if you have wrong credentials you should see the error type.
In CodeIgniter (CI) is very easy to work with Database.
See:
http://ellislab.com/codeigniter/user-guide/database/examples.html
Try changing
$db['default']['hostname'] = '127.0.0.1';
to
$db['default']['hostname'] = 'localhost';
make sure for the password as well
Ok, so it looks like everything started working fine as soon as I uncommented this line in php.ini: extension=php_mysql.dll
However why it was not returning any errors in CI ?
Are you sure you are in "development" mode? (look at the beginning of the index.php)
What happens if you manually trigger an error? trigger_error('blah blah', E_USER_ERROR);
edit: The problem may be because CodeIgniter masks many SQL-related errors (for instance see this recent issue). The easiest solution to debug your code would be to install Xdebug and enable the scream option.
<?php
class Blog extends CI_Controller {
public function index()
{
echo 'Hello World!';
}
}
?>
I read the user guide carefully and try to run the code.first i create code in notepad which are above and then save it to the application/controller.but it give the error
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: D:\xampp\htdocs\ci_intro\system\database\DB_driver.php
Line Number: 124
which is to be made change to run this code successfully.please anyone can help me.i am a primary user of codeigniter.so i don't understand the error.
Seems that you are trying to connect to database. If that is the case check your settings in config/database.php
If you don't want to connect to database, check your config/autoload.php and make sure that you are not autoloading the database library.
http://ellislab.com/codeigniter/user-guide/database/connecting.html
If you want to use database then you should fill out the config/database.php with the mysql db info. (I see you are using xampp so DB Driver would be mysql I suppose)
Lets say we have following database information: databaseName, databaseUser and databasePassword;
Soo the database.php would be filled out like this:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'databaseUser';
$db['default']['password'] = 'databasePassword';
$db['default']['database'] = 'databaseName';
$db['default']['dbdriver'] = 'mysql';
you wrote a right code. this error occur when you try to connect to your database with wrong config. to change your configuration go to application > config folder and open database.php file.
in that you see some config like this.
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'databaseName';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
before these configs they completely described and say how you can use them. read them and set your config.
this reference is useful to understand how you can config your database. if you config your database you can run your code without any problem.
I know this sounds so repost several times. But I cannot get it resolved.
I tried to connect my application to mysql, these are what I have tried (I tried only one out of these options, not both):
$autoload['libraries'] = array('database'); on application\config\autoload.php, but I got Fatal error: Call to a member function get() on a non-object in /Users/zakkafm/Sites/CodeIgniter/application/models/My_models.php on line 15
$this->load->database(); on application\models\My_models.php on __construct() (also I added parent::__construct(), but I got Fatal error: Call to a member function database() on a non-object in /Users/zakkafm/Sites/CodeIgniter/application/models/My_model.php on line 7
So, what could be wrong here?
EDIT:
this is my database.php looks like.
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'trial';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
RESOLVED!!!
After all, this is all because of the autocomplete on Eclipse I added on system/core/Controller.php and system/core/Model.php.
Hmm.., I think you don't have to add
$this->load->database();
on your My_models.php, coz as I know it will be automatically connected to the database as you set on the database.php file. So, remove it from My_models.php file & try again.
Hope it helps :)
In you My_models.php you shouldn't be calling $this->load->database(); should just have:
class My_models extends CI_Model {
/**
* Constructor
*/
function __construct()
{
parent::__construct();
}
function something(){
// your model code goes here
}
}
Also you only need to enable the autoload and you are good to go (keeping in mind that the MYSQL library needs to be loaded for PHP.
And you might have an error here (don't see your code so not sure):
Fatal error: Call to a member function get() on a non-object in
/Users/zakkafm/Sites/CodeIgniter/application/models/My_models.php on line 15
In my database.php file, I have
$db['default']['hostname'] = 'mylocaldomain:8889';
$db['default']['username'] = 'myusername';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'mydb';
$db['default']['dbdriver'] = 'mysql';
I continually, get an error saying that it can't connect. Any help?
Try changing:
$db['default']['hostname'] = 'mylocaldomain:8889';
To:
$db['default']['hostname'] = 'localhost';
or:
$db['default']['hostname'] = '127.0.0.1';
I think you're confusing your apache server's host/port with MySQL's host