Location: PHPKode > projects > Esvon Personals > esvon-personals/inc/pdo.inc.php
<?php

if(!function_exists('mysql_connect') && class_exists('PDO')){

// PDO workaround, use as transparent layer to move to PDO

  class esPDO extends PDO {
    var $_aff_rows = 0;
    function exec($sql){
      return $this->_aff_rows = parent::exec($sql);
    }
    function affected_rows(){ return $this->_aff_rows; }
  }

  function mysql_connect($server,$user,$pass){ 
    try {
      return new esPDO('mysql:host='.$server, $user, $pass); // ;dbname=
    } catch (PDOException $e) { die($e->getMessage()); }
  }
  function mysql_fetch_row($st) { return $st->fetch(PDO::FETCH_NUM); }
  function mysql_fetch_assoc($st) { return $st->fetch(PDO::FETCH_ASSOC); }
  function mysql_data_seek($st,$i) { // temp. solution ??
    if($i==0){ 
      // $st->closeCursor();
      $st->execute();
    }
    else trigger_error('N/a in PDO mode', E_USER_ERROR);
  }
  function mysql_free_result($st) { unset($st); }
  function mysql_num_rows($st) { return $st->rowCount(); }
  function mysql_error($conn) { $v = $conn->errorInfo(); return $v[2]; }
  function mysql_errno($conn) { return $conn->errorCode(); }
  function mysql_real_escape_string($s, $conn) { return substr($conn->quote($s, PDO::PARAM_STR),1,-1); }
  function mysql_query($sql, $conn) { 
    if(preg_match('/^(?:DELETE|UPDATE|INSERT)/i', $sql)) return $conn->exec($sql);
    return $conn->query($sql);
  }
  function mysql_insert_id($conn) { return $conn->lastInsertId(); }
  function mysql_affected_rows($conn) { 
    return $conn->affected_rows();
  }
  function mysql_get_server_info($conn) { return $conn->getAttribute(PDO::ATTR_SERVER_VERSION); }
  function mysql_select_db($name,$conn) { 
    $conn->query('USE '.$name); 
    return true;
  }
  function mysql_num_fields($st) { return $st->columnCount(); }
  function mysql_field_name($st, $i){
    $finfo = $st->getColumnMeta($i); // experimental func
    return $finfo['name'];
  }

}

?>
Return current item: Esvon Personals