COOKIE['session_api_session'] not working in drupal 7
Quoting value with " characters in MySQL is wrong. The MySQL string quote is '. The " character is the character used to quote table or columns names. With an empty value in $cookieid you have an SQL query searching session-id equals to a column named empty string, this is the 


  PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause': SELECT sid FROM {session_api} WHERE session_id = ""; 


with 'foo' as session uid you would have a query searching for rows having session_id columns equals to value of "foo" column. It would also be wrong.

Use Drupal helpers to write queries. Field and value escapes will be the right ones for the right engine:

$sid = db_query(
  'SELECT sid FROM {session_api}  WHERE session_id = %my_sid',
   array('%my_sid' =&gt; $cookieid
)-&gt;fetchField();


Or even more D7 (untested but it's something like that):

 $query= db_select('session_api','s');
 $query-&gt;fields('s','sid');
 $query-&gt;conditions('sid',$cookieid,'=');
 $sid = $query-&gt;fetchField();


now the 1st error message says there is nothing in $_COOKIE['session_api_session']. So you should enclose your code in a:

if (array_key_exists('session_api_session',$_COOKIE) 
 &amp;&amp; !empty($_COOKIE['session_api_session'])) {
   ...
}


At least you will avoid the warnings and errors.

About session api usage I would certainly better use session api functions to retrieve the current id, something like session_api_get_sid():

/**
 * Return a Session API ID corresponding to the current session.
 * The session id is a created using the same method as Drupal core
 * as defined in includes/session.inc.
 * @param boolean create set this to FALSE if you don't want to create a session
 * cookie if it doesn't already exist.
 */
function session_api_get_sid($create = TRUE) {