DB_common(); $this->phptype = 'rpc'; $this->dbsyntax = 'rpc'; $this->features = array( 'prepare' => false, 'pconnect' => false, 'transactions' => false, 'limit' => 'alter' ); $this->errorcode_map = array( 1004 => DB_ERROR_CANNOT_CREATE, 1005 => DB_ERROR_CANNOT_CREATE, 1006 => DB_ERROR_CANNOT_CREATE, 1007 => DB_ERROR_ALREADY_EXISTS, 1008 => DB_ERROR_CANNOT_DROP, 1046 => DB_ERROR_NODBSELECTED, 1050 => DB_ERROR_ALREADY_EXISTS, 1051 => DB_ERROR_NOSUCHTABLE, 1054 => DB_ERROR_NOSUCHFIELD, 1062 => DB_ERROR_ALREADY_EXISTS, 1064 => DB_ERROR_SYNTAX, 1100 => DB_ERROR_NOT_LOCKED, 1136 => DB_ERROR_VALUE_COUNT_ON_ROW, 1146 => DB_ERROR_NOSUCHTABLE, ); } // }}} // {{{ connect() /** * Connect to a database and log in as the specified user. * * @param $dsn the data source name (see DB::parseDSN for syntax) * @param $persistent (optional) whether the connection should * be persistent * @access public * @return int DB_OK on success, a DB error on failure */ function connect($dsninfo, $persistent = false) { $this->dsn = $dsninfo; $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost'; $user = $dsninfo['username']; $pw = $dsninfo['password']; return DB_OK; } // }}} // {{{ disconnect() /** * Log out and disconnect from the database. * * @access public * * @return bool TRUE on success, FALSE if not connected. */ function disconnect() { $this->connection = null; return TRUE; } // }}} // {{{ simpleQuery() /** * Send a query to MySQL and return the results as a MySQL resource * identifier. * * @param the SQL query * * @access public * * @return mixed returns a valid MySQL result for successful SELECT * queries, DB_OK for other successful queries. A DB error is * returned on failure. */ function simpleQuery($query) { $this->connectionid++; $this->result[$this->connectionid] = $this->send_query($query); $ret = new DB_rpc_result(); $ret->id = $this->connectionid; $result->rownum[$this->connectionid] = 0; return $ret; // if (!$this->result) { // return $this->mysqlRaiseError(); // } // return "r1"; } function parse_dsn () { echo serialize($this->dsn); $ret["user"] = $this->dsn["username"]; $ret["password"] = $this->dsn["password"]; $ret["url"]= $this->dsn["hostspec"]; $ret["database"] = $this->dsn["database"]; $p = strpos($this->dsn["hostspec"],"?"); $ret["url"] = substr($this->dsn["hostspec"],0,$p); $ret["remotedsn"] = substr($this->dsn["hostspec"],$p+1); return $ret; } function send_query($query) { echo("RPC CURL: $query"); // dsn format // mysql://user:password@host/database // rpc format // rpc://user:password@http://host:port/url?mysql://user:password@host/database // rpc://user:password@host/url?mysql://user:password@host/database $connect = $this->parse_dsn(); $URL = $connect["url"] ; $request_obj = new request(); $request_obj->database = $connect["database"]; $request_obj->sql = $query; $postarray["request"] = serialize($request_obj); echo "$URL?request=".urlencode($postarray["request"]) . "\n"; $ch = curl_init(); $poststring = ""; if ($postarray) foreach ($postarray as $k => $v) $poststring .= "&" .urlencode($k)."=". urlencode($v); $poststring = substr($poststring,1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $poststring); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); echo "CONNECT WITH " . $connect["user"].":".$connect["password"] . "\n"; curl_setopt ($ch, CURLOPT_USERPWD, $connect["user"].":".$connect["password"]); curl_setopt ($ch, CURLOPT_URL, $URL); curl_setopt ($ch,CURLOPT_SSLVERSION, 3); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch,CURLOPT_SSL_VERIFYHOST, 1); curl_setopt ($ch, CURLOPT_WRITEFUNCTION, array(&$this,"curl_read")); echo ("EXEC"); $this->curl_result = ""; $result = curl_exec ($ch); //echo curl_error($ch); $this->curlinfo = curl_getinfo($ch); curl_close($ch); echo $this->curl_result; $this->result_obj = unserialize($this->curl_result); return $this->result_obj->data; } function curl_read($ch,$string) { $len = strlen($string); if (class_exists("Gtk")) while (gtk::events_pending()) gtk::main_iteration(); $this->curl_result .= $string; return $len; } // }}} // {{{ nextResult() /** * Move the internal mysql result pointer to the next available result * * @param a valid fbsql result resource * * @access public * * @return true if a result is available otherwise return false */ function nextResult($result) { return false; } // }}} // {{{ fetchRow() /** * Fetch and return a row of data (it uses fetchInto for that) * @param $result MySQL result identifier * @param $fetchmode format of fetched row array * @param $rownum the absolute row number to fetch * * @return array a row of data, or false on error */ function fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) { if ($fetchmode == DB_FETCHMODE_DEFAULT) { $fetchmode = $this->fetchmode; } $res = $this->fetchInto ($result, $arr, $fetchmode, $rownum); if ($res !== DB_OK) { return $res; } return $arr; } // }}} // {{{ fetchInto() /** * Fetch a row and insert the data into an existing array. * * @param $result MySQL result identifier * @param $arr (reference) array where data from the row is stored * @param $fetchmode how the array data should be indexed * @param $rownum the row number to fetch * @access public * * @return int DB_OK on success, a DB error on failure */ function fetchInto($result, &$arr, $fetchmode, $rownum=null) { $id = $result->id; echo "\nFETCHINTO:$rownum\n". serialize($result) . "\n conneciton $id, currow".$this->rownum[$id]."\n"; if ($rownum !== null) { $arr = $this->result[$id][$row]; return DB_OK; } $arr=NULL; if (!@$this->result[$id][$this->rownum[$id]*1]) return NULL; //echo "ROWNUM :" . $this->rownum; if ($fetchmode != DB_FETCHMODE_ASSOC) { $arr = array_values ($this->result[$id][$this->rownum[$id]*1] ); } else { $arr = $this->result[$id][$this->rownum[$id]*1]; } $this->rownum[$id]++; return DB_OK; } // }}} // {{{ freeResult() /** * Free the internal resources associated with $result. * * @param $result MySQL result identifier or DB statement identifier * * @access public * * @return bool TRUE on success, FALSE if $result is invalid */ function freeResult($result) { unset($this->result); $this->rownum=0; return true; } // }}} // {{{ numCols() /** * Get the number of columns in a result set. * * @param $result MySQL result identifier * * @access public * * @return int the number of columns per row in $result */ function numCols($result) { $cols = count($this->result[0]); if (!$cols) { return $this->mysqlRaiseError(); } return $cols; } // }}} // {{{ numRows() /** * Get the number of rows in a result set. * * @param $result MySQL result identifier * * @access public * * @return int the number of rows in $result */ function numRows($result) { $rows = count($this->result); if ($rows === null) { return $this->mysqlRaiseError(); } return $rows; } // }}} // {{{ autoCommit() /** * Enable/disable automatic commits */ function autoCommit($onoff = false) { // XXX if $this->transaction_opcount > 0, we should probably // issue a warning here. return $this->mysqlRaiseError(); } // }}} // {{{ commit() /** * Commit the current transaction. */ function commit() { return $this->mysqlRaiseError(); } // }}} // {{{ rollback() /** * Roll back (undo) the current transaction. */ function rollback() { return $this->mysqlRaiseError(); } // }}} // {{{ affectedRows() /** * Gets the number of rows affected by the data manipulation * query. For other queries, this function returns 0. * * @return number of rows affected by the last query */ function affectedRows() { return $this->mysqlRaiseError(); } // }}} // {{{ errorNative() /** * Get the native error code of the last error (if any) that * occured on the current connection. * * @access public * * @return int native MySQL error code */ function errorNative() { return $this->mysqlRaiseError(); } // }}} // {{{ nextId() /** * Get the next value in a sequence. We emulate sequences * for MySQL. Will create the sequence if it does not exist. * * @access public * * @param $seq_name the name of the sequence * * @param $ondemand whether to create the sequence table on demand * (default is true) * * @return a sequence integer, or a DB error */ function nextId($seq_name, $ondemand = true) { return $this->mysqlRaiseError(); } // }}} // {{{ createSequence() function createSequence($seq_name) { return $this->mysqlRaiseError(); } // }}} // {{{ dropSequence() function dropSequence($seq_name) { return $this->mysqlRaiseError(); } // }}} // {{{ quote() /** * Quote the given string so it can be safely used within string delimiters * in a query. * @param $string mixed Data to be quoted * @return mixed "NULL" string, quoted string or original data */ function quote($str = null) { return $this->mysqlRaiseError(); } // }}} // {{{ modifyQuery() function modifyQuery($query, $subject = null) { return $this->mysqlRaiseError(); } // }}} // {{{ modifyLimitQuery() function modifyLimitQuery($query, $from, $count) { return $this->mysqlRaiseError(); } // }}} // {{{ mysqlRaiseError() function mysqlRaiseError($errno = null) { return $this->mysqlRaiseError(); } // }}} // {{{ tableInfo() function tableInfo($result, $mode = null) { return $this->mysqlRaiseError(); } // }}} // {{{ getTablesQuery() /** * Returns the query needed to get some backend info * @param string $type What kind of info you want to retrieve * @return string The SQL query string */ function getSpecialQuery($type) { return $this->mysqlRaiseError(); } // }}} // TODO/wishlist: // longReadlen // binmode } ?>