Back to index

php5  5.3.10
interbase.inc
Go to the documentation of this file.
00001 <?php /* $Id: interbase.inc 267053 2008-10-07 12:51:21Z felipe $ */
00002 
00003 srand((double)microtime()*1000000);
00004 
00005 $user = 'SYSDBA';
00006 $password = 'masterkey';
00007 ini_set('ibase.default_user',$user);
00008 ini_set('ibase.default_password',$password);
00009 
00010 /* we need just the generated name, not the file itself */
00011 unlink($test_base = tempnam('/tmp',"php_ibase_test"));
00012 
00013 function init_db()
00014 {
00015        global $test_base, $user, $password;
00016 
00017        $test_db = ibase_query(IBASE_CREATE, 
00018               sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$test_base,
00019               $user, $password, ($charset = ini_get('ibase.default_charset')) ? $charset : 'NONE'));
00020        $tr = ibase_trans($test_db);
00021        ibase_query($tr,"create table test1 (i integer, c varchar(100))");
00022        ibase_commit_ret($tr);
00023        ibase_query($tr,"insert into test1(i, c) values(1, 'test table not created with isql')");
00024        ibase_commit($tr);
00025        ibase_close($test_db);
00026 }
00027 
00028 function cleanup_db()
00029 {
00030        global $test_base;
00031     
00032        $r = ibase_connect($test_base);
00033        ibase_drop_db($r);
00034 }
00035 
00036 register_shutdown_function('cleanup_db');
00037 init_db();
00038 
00039 function out_table($table_name)
00040 {
00041        echo "--- $table_name ---\n";
00042        $res = ibase_query("select * from $table_name");
00043        while ($r = ibase_fetch_row($res)) {
00044               echo join("\t",$r)."\t\n";
00045        }
00046        ibase_free_result($res);
00047        echo "---\n";
00048 }
00049 
00050 function out_result($result, $table_name = "")
00051 {
00052        echo "--- $table_name ---\n";
00053        while ($r = ibase_fetch_row($result)) {
00054               echo join("\t",$r)."\t\n";
00055        }
00056        echo "---\n";
00057 }
00058 
00059 function out_result_trap_error($result, $table_name = "")
00060 {
00061    echo "--- $table_name ---\n";
00062    while ($r = @ibase_fetch_row($result)) {
00063               echo join("\t",$r)."\t\n";
00064    }
00065    echo "errmsg [" . ibase_errmsg() . "]\t\n";
00066    echo "---\n";
00067 }
00068 
00069 /* M/D/Y H:M:S */
00070 function rand_datetime()
00071 {
00072     return sprintf("%02d/%02d/%4d %02d:%02d:%02d",
00073               rand()%12+1, rand()%28+1, rand()%100+1910,
00074               rand()%24,   rand()%60,  rand()%60);
00075 }
00076 
00077 /* random binary string  */
00078 function rand_binstr($max_len)
00079 {
00080     $len = rand() % $max_len;
00081     $s = "";
00082     while($len--) {
00083         $s .= sprintf("%c", rand() % 256);
00084     }
00085     return $s;
00086 }
00087 
00088 function rand_str($max_len)
00089 {
00090     $len = rand() % $max_len;
00091     $s = "";
00092     while ($len--) {
00093         $s .= sprintf("%c", rand() % 26 + 65);
00094     }
00095     return $s;
00096 }
00097 
00098 function rand_number($len , $prec = -1, $sign = 1)
00099 {
00100     if ($prec == -1) {
00101         $n = substr(rand() . rand(), 0, rand() % $len + 1);
00102         if (strlen($n) < $len) {
00103               $n .= "." . substr(rand(), 0, rand() % ($len - strlen($n)) + 1);
00104         }
00105     } else if ($prec == 0) {
00106         $n = substr(rand() . rand(), 0, rand() % $len + 1);
00107     } else if (($prec - $len) == 0) {
00108         $n = substr(rand() . rand(), 0, 1);
00109         $n .= "." . substr(rand(), 0, $prec);
00110     } else {
00111         $n = substr(rand() . rand(), 0, rand() % ($len - $prec) + 1);
00112         $n .= "." . substr(rand(), 0, $prec);
00113     }
00114     if ($sign && (rand() % 3 == 0)) {
00115         $n = "-" .$n;
00116     }
00117     return $n;
00118 }
00119 
00120 ?>