Skip to main content
  1. Tech/

MySQL Update If Exist Else Insert Procedure

·1 min

Are you tired of checking data in your code before inserting? Well MySQL procedures are here to the rescue. This simple procedure shows how you can do that:

CREATE PROCEDURE   ` update_insert_user ` (  IN  uid2 int  )
 BEGIN
 DECLARE  last_login2 DATETIME;
 SELECT   ` last_login ` INTO  last_login2  FROM   `  user  ` WHERE   ` uid `   =  uid2  LIMIT   1 ;
 IF  last_login2  IS NULL THEN
 INSERT INTO   `  user  `  ( ` uid ` , ` last_login ` )  values  (uid2, now());
 ELSE
 UPDATE   `  user  ` SET   ` last_login `   =  now()  WHERE   ` uid `   =  uid2  LIMIT   1 ;
 END IF ;
 END

Related

Codeigniter Creates a New Session With Each Page Load

·1 min
Just spent 3 hours debugging a session bug in my webapp. CodeIgniter was creating a brand new session with each page load. The issue was a misconfiguration with my config file. Fix was simple, in /application/config/config.php, make sure the correct domain is set for $config['cookie_domain'].

Codeigniter Out of Memory Error

·1 min
Query Saving is a feature of CI’s database class that stores the results of every query in memory until the controller is finished executing. As it turns out, in version 1.6.0, the ability to turn this off was added. The addition of the save_queries variable is listed in the Change Log, but as of the latest release of 2.0.0 last week, it still hasn’t made the documentation. $this->db->save_queries = FALSE; via Undocumented CodeIgniter | Green Egg Media.

ssh_exchange_identification: Connection closed by remote host

·1 min
I tried to login to my server tonight but kept getting the following error message: ssh_exchange_identification: Connection closed by remote host The fix was simple, at least if you have access to the server via cPanel. Just restart sshd service via cPanel/WHM.