I have simple PHP code.

/************************************** DB

class db {

  var $connect_id;

  function open( $database, $host, $user, $password ) {
    $this->connect_id = @sybase_connect( $host, $user, $password );
    if ( $this->connect_id ) {
      $result = @sybase_select_db( $database );
      if ( !$result ) {
        $this->connect_id = $result;
      return $this->connect_id;
    } else {
      return 0;

}; // End class

/************************************** QUERY

class query {
  var $result;
  var $was_error;

  function query( &$db, $query = "" ) {
    global $php_errormsg;
    global $GLOBALS;


    //remove comment sings at line below to get OK result
    //$query = "select * from mytab";
    $this->result = @sybase_query( $query, $db->connect_id );
    if( $this->result == FALSE ) {
      $fh = fopen( "/tmp/syberror.log", "a" );
      fwrite( $fh, 'PHP_ERRORMSG:' . $php_errormsg . "\n" );
      fwrite( $fh, 'PHP_ERRORMSG:' . $GLOBALS[ "php_errormsg" ] . "\n"
      fwrite( $fh, $query."\n" );
      fclose( $fh );
      $this->was_error = 1;

  function error() {
    if( $this->was_error )
      $result = 1;
      $result = 0;

    return $result;

}; // End class


 $DB = new db();
 $DB->open( $dbName, $dbServer, $dbUser, $dbPass );
 $q = new query($DB); //dummy query for generic operations

 $query = "select * from mytab";
 $q->query( $DB, $query ); //there is called query

 if ( $q->error() ) {
  //I always get WRONG when doesn't change the value of $query paramater
inside query() method
  print( 'WRONG' );
 } else {
  //I always get OK when change the value of $query paramater inside
query() method
  print( 'OK' );


When I run script above I got WRONG message. Then I changed value of the
$query parameter inside query method of query class and rerun the script
then I got OK. Funny, isn't it ???. What is it wrong ??? It is NOT MY
FIRST TIME when I'm using PHP, Apache and Sybase Adaptive Server
Enterprise. Till this time I've never used class for connecting and
querying database. I have my own scripts to connect/query SYBASE
database, but I tried to use classes. It's more useful and powerful.

Second problem. How to get values of the global variables inside methods
of any class ??? Code inside method query() doesn't return values of
global variable $php_errormsg (trace error flag is ON).

Thanks for any help

Krzysztof Kocjan

Zapal lampe w sypialni!
Swiatlo wzmaga apetyt na seks.

PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to