codeigniter A Database Error Occurred - codeigniter

Can someone help me?
I am a beginner and trying to make wearing CodeIgniter authentication, but when I try to make an error like this
A Database Error Occurred
Error Number: 1046
No database selected
SELECT * FROM (`user`) WHERE `user_username` = 'amanda' AND user_passwordMD5("12345") =
Filename: C:\xampp\htdocs\codeigniter\system\database\DB_driver.php
Line Number: 330
thanx

please make sure you have setup database configuration in application/config/database.php file
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'my_database';

Check the database.php file in application/config/
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'my_database'; // here is the database selection

Open the file application/config/database.php file and change the following line:
$db['default']['dbdriver'] = 'mysql';
To:
$db['default']['dbdriver'] = 'mysqli';
This shift to mysqli saved by day.

Lost connection to MySQL server during query
Line Number: 337

people who critic here should have not only education but also common sense. they should know also what time I made this comment and what was my reputation score. It is not only about giving an answer but the giving also the suggestion a beginner can pin-point the problem. I could have given the answer but just after posting my comment someone already given answer. Look below - best among anyone given here
$config['hostname'] = "localhost";
$config['username'] = "username";
$config['password'] = "password";
$config['database'] = "database";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";

Related

php mailer subject utf8

my mail form works very well. there is only problem in the subject line. If there is the letter "şğüöç" in the mail, the subject line is empty. It shows like this in MS Outlook program. =? Utf-8? Q ?? =
If there are no letters "şğüöç", the subject line is correct. I have read many articles. but i couldn't my head hurts, my brain burned.
<?php
require ("class.phpmailer.php");
$gittiMesaji = " ";
if(isset($_POST['submit'])){
$isimsoyisim =$_POST['isimsoyisim'];
$telefon =$_POST['telefon'];
$email =$_POST['email'];
$dogumtarihi =$_POST['dogumtarihi'];
$tckimlik =$_POST['tckimlik'];
$yabanci =$_POST['yabanci'];
$dogumyeri =$_POST['dogumyeri'];
$askerlik =$_POST['askerlik'];
$ehliyet =$_POST['ehliyet'];
$medeni =$_POST['medeni'];
$evlenmetarih =$_POST['evlenmetarih'];
$esbilgileri =$_POST['esbilgileri'];
$cocuk =$_POST['cocuk'];
$ikamet =$_POST['ikamet'];
$sabika =$_POST['sabika'];
$temas =$_POST['temas'];
$okul1 =$_POST['okul1'];
$okul1sehir1 =$_POST['okul1sehir1'];
$okul1mezuniyettarih1 =$_POST['okul1mezuniyettarih1'];
$okul2 =$_POST['okul2'];
$okul2sehir2 =$_POST['okul2sehir2'];
$okul2mezuniyettarih2 =$_POST['okul2mezuniyettarih2'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.yandex.com';
$mail->SMTPAuth = true;
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = 'no-reply#xxxxxxxxx.com';
$mail->Password = '**********';
$mail->CharSet = 'utf-8';
$mail->Encoding = 'base64';
$mail->From = 'no-reply#xxxxxxxxx.com';
$mail->FromName = 'Saffan Global';
$mail->AddAddress ($email);
$mail->AddCC ('webmaster#xxxxxxxxx.com');
$mail->IsHTML(true);
$mail->Subject = 'Basvuru - ' .$isimsoyisim;
// HTML Message Starts here
$mail->Body = "
<html>
<body>
<table style='width:90%' align='center';>
<tbody>

How to hash last insert id and set into request then save into db in laravel.?

Below my request is perfectly fine. I just wonder is it best way to use save function two time?.its really bothering me I am looking for a best way to hashed last insert id and set into visitor_id to save into db.
Remember before hashing visitor_id i am sending $request->visitor_id NULL.
Here is my request:
$visit->funnel_id = $request->funnel_id;
$visit->page_id = $request->page_id;
$visit->traffic_source_id = $request->traffic_source_id;
$visit->visitor_id = $request->visitor_id;
$visit->save();
$hashid = new Hashid();
$visit->visitor_id = $hashid->encode($visit->id);
$visit->save();
You can add 'nextId' function and include Illuminate\Support\Facades\DB facade in your Visitor model.
public function nextId(){
$statement = DB::select("SHOW TABLE STATUS LIKE '".$this->getTable()."'");
return $statement[0]->Auto_increment;
}
You can implement in your code like this :
$visit->funnel_id = $request->funnel_id;
$visit->page_id = $request->page_id;
$visit->traffic_source_id = $request->traffic_source_id;
$hashid = new Hashid();
$visit->visitor_id = $hashid->encode($visit->nextId());
$visit->save();
$visit->funnel_id = $request->funnel_id;
$visit->page_id = $request->page_id;
$visit->traffic_source_id = $request->traffic_source_id;
$visit->visitor_id = $request->visitor_id;
$visit->save();
$hashid = new Hashid();
$hashid->visitor_id = $visit->id;
$hashid->save();
Try
$hashid = new Hashid();
$visit->visitor_id = $hashid->\Hash::make($visit->id);
$visit->save();
Or
$hashid = new Hashid();
$visit->visitor_id = $hashid->$visit->id;
$visit->save();

Codeigniter : pagination with query string is not working properly

I am using query string pagination. I have integrated this successfully. There are some issue with this.
when i click on second page first time it reloads the page but doesn't append ?per_page to the URL, it does appends like this controller/method/?2
when i click on second page second time it does the correct behavior but URL becomes like this controller/method/parameter/?0=&per_page=2
but the URL should be if there are not other get parameter
controller/method/parameter/?per_page=2
how to get this issue fixed ? i have enabled query string like this
$config['page_query_string'] = true;
$config['reuse_query_string'] = true;
Can anyone suggest what is the wrong in this implementation ? My base url is
$config['base_url'] = base_url().'controller/method/parameter/';
Basically it is not adding per_page query string if there is no query string already there in URL. How can i fix that ?
$config["total_rows"] = 200;
$config["per_page"] = 10;
$config['num_links'] = 4;
$config['page_query_string']= TRUE;
$config['use_page_numbers'] = TRUE;
$config["base_url"] = base_url().'controller/method/';
//Change uri segment according your url
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$links = $this->pagination->create_links();

Why the Codeigniter session does not expire after closing the browser?

Problem scenario
If a user A logs into the application then the user id set in session. After doing some tasks user A closes his browser and leaves the computer. Short time later, user B came and open browser and see the application was in logged in state. User B can also open an internal url, which directly redirects him into the application without any authentication by using the previous session.
My Configuration
$config['sess_cookie_name'] = 'cisession';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = TRUE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
You can override or Set a Config Item dynamically. If you simply look at $config['sess_expire_on_close'] = TRUE;
Whether to make the session to expire automatically when the browser window is closed.
Set it to true if user did not check the remember me checkbox. And the session will expire after user close the browser.
And if he checks the remember me checkbox, set $config['sess_expire_on_close'] to FALSE like
if($this->input->post('remember')) $this->config->set_item('sess_expire_on_close', '0'); //'remember' is checkbox name.
now session will not expire after browser is closed.
note: this solution is also tested on Opera, Mozilla, Chrome and ie9
Try this, may be it help you
/ **
* Escape String
*
* #param string
* #param bool whether or not the string will be used in a LIKE condition
* #return string
*/
public function escape_str($str, $like = FALSE)
{
if (is_array($str))
{
foreach ($str as $key => $val)
{
$str[$key] = $this->escape_str($val, $like);
}
return $str;
}
$str = is_resource($this->conn_id) ? mysql_real_escape_string($str, $this->conn_id) : addslashes($str);
// escape LIKE condition wildcards
if ($like === TRUE)
{
return str_replace(array($this->_like_escape_chr, '%', '_'),
array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
$str);
}
return $str;
}
// --------------------------------------------------------------------
Set in application/config/config.php:
$config['sess_expiration'] = 0;
$config['sess_expire_on_close'] = TRUE;
This should be OK.
Why don't you use the CI session function to do that
http://www.codeigniter.com/userguide2/libraries/sessions.html

Codeigniter sessions issue

I am using codeigniter. I have a weird problem with the sessions. I set the session when the user logs in and redirects him to a new page. I observe that the sessions are set sometimes and sometimes they aren't set. I have tried using codeigniter sessions & native sessions with sess_use_database variable TRUE and FALSE. I have no idea of what's going on.
This is how the config file looks like:
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 7200;
When session data is available in a database, every time a valid session is found in the user's cookie, a database query is performed to match it. If the session ID does not match, the session is destroyed. Session IDs can never be updated, they can only be generated when a new session is created.
In order to store sessions, you must first create a database table for this purpose.
Create it in your DB:
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(120) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id),
KEY `last_activity_idx` (`last_activity`)
);
When, go at config and and change:
$config['sess_use_database'] = TRUE;
I prefer to save the session in database because it is more secure and works without problem.
Where is your sess_cookie setting? I dont see it there?
$config['sess_cookie_name'] = 'cookiename';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 7200;
Make sure whatever cookie name you pick does NOT have an underscore. i.e:
$config['sess_cookie_name'] = 'mycookie'; // good
$config['sess_cookie_name'] = 'my_cookie'; // bad
Had the same issue and what I found it having
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
Will insert 2 records in the session table, the first record with the data and the second record with nothing hence the session data not accessible. When you change
$config['sess_encrypt_cookie'] = FALSE;
to false it will only insert one record into the session table with all the data and all will be right with the world :)
I think that it's just not getting updated as supposed and it creates a new one on every page request. (common Codeigniter's setting issue)
here's my suggestions:
double check your Application/Config/config.php file to ensure that the part of session domain looks like that if you host the site on the main directory:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "yourdomain.com";
$config['cookie_path'] = "var/sessions/";
$config['cookie_secure'] = FALSE;
and like that if you host the site on a sub-directory:
$config['cookie_prefix'] = "";
$config['cookie_domain'] = "yourdomain.com";
$config['cookie_path'] = "siteSubDirectory/var/sessions/";
$config['cookie_secure'] = FALSE;
and also make sure that the 2 directories are writable by fixing their permissions to 755 or so, and I strongly recommend that you enable database session, it's more secure and will help you find out the real problem by checking the session table. good luck :)
try $config['sess_match_useragent'] = FALSE;
i'm experiencing the same issue with sessions and redirects and i've hacked my cms to find out what's causing this. setting that in config.php worked for me.

Resources