Logo Search packages:      
Sourcecode: dbtcp version File versions  Download package

test-dbtcp.php

<?PHP
   /*
      Connect to a non existent server
   */
   $DSN="DSN=dbAnticipi";
   $SERVER="192.168.26.41";
   $PORT=3000;
   $QUERY="SELECT * FROM tAnticipi";

   /*
      Connect to a fake server
   */
   echo "<PRE>This connection fails\n";
   $id=dbtcp_connect ( $DSN, "127.0.0.1", 3000 );
   if ( $id == FALSE ) {
      echo "Connection error\n";
   }

   echo "Query and fetch\n";
   /*
      Connect to a real server
   */
   $id=dbtcp_connect ( $DSN, $SERVER, $PORT );
   if ( $id == FALSE ) {
      echo "Connection error\n";
   }
   else
   {
      echo "Connected ID=" . $id . "\n";
   }

   /*
      Make a query
   */
   $res=dbtcp_sql ( $QUERY, $id );
   if ( $res == TRUE ) {
      echo "Connected\n";
   }
   else {
      echo "Error ". dbtcp_error($id) . "\n";
   }

   /*
      Fetch some result info
   */
   $idx=0;
   $num_fields=dbtcp_num_fields ( $id );
   while ( $idx < $num_fields ) {
      list( $field, $type, $length )=dbtcp_field_info( $id, $idx );
      echo "FIELD $idx - NAME '$field' - TYPE '$type' - LENGTH '$length'\n";
      $field_name[$idx]=$field;
      $idx += 1;
   }

   /*
      Fetch the result set
   */
   $idx=1;
   while ( list ( $idant, $num1, $num2, $str1, $valuta, $valore ) = dbtcp_fetch ( $id ) )
   {
      echo "ROW $idx) $idant, $num1, $num2, $str1, $valuta, $valore\n";
      $idx += 1;
   }
   echo "Rows $idx\n";

   /*
      Make a query
   */

   $res=dbtcp_sql ( $QUERY, $id );
   if ( $res == TRUE ) {
      echo "Connected\n";
   }
   else {
      echo "Error ". dbtcp_error($id) . "\n";
   }

   /*
      Fetch the result set
   */
   echo "Query and fetch associative\n";
   $idx=1;
   while ( $array = dbtcp_fetch_assoc ( $id ) )
   {
      echo "ROW $idx) ";
      foreach ( $array  as $c => $v )
      {
         echo "$c='$v' ";
      }
      echo "\n";
      $idx += 1;
   }
   echo "Rows $idx\n</PRE>";

   /*
      Close connection
   */
   dbtcp_close ( $id );
?>

Generated by  Doxygen 1.6.0   Back to index