Adodb Dokumentation  V5.14 8 Sept 2011
tests/test-php5.php
00001 <?php
00002 /*
00003   V4.81 3 May 2006  (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved.
00004   Released under both BSD license and Lesser GPL library license. 
00005   Whenever there is any discrepancy between the two licenses, 
00006   the BSD license will take precedence.
00007   Set tabs to 8.
00008  */
00009 
00010 
00011 error_reporting(E_ALL);
00012 
00013 $path = dirname(__FILE__);
00014 
00015 include("$path/../adodb-exceptions.inc.php");
00016 include("$path/../adodb.inc.php");      
00017 
00018 echo "<h3>PHP ".PHP_VERSION."</h3>\n";
00019 try {
00020 
00021 $dbt = 'oci8po';
00022 
00023 try {
00024 switch($dbt) {
00025 case 'oci8po':
00026         $db = NewADOConnection("oci8po");
00027         
00028         $db->Connect('localhost','scott','natsoft','sherkhan');
00029         break;
00030 default:
00031 case 'mysql':
00032         $db = NewADOConnection("mysql");
00033         $db->Connect('localhost','root','','northwind');
00034         break;
00035         
00036 case 'mysqli':
00037         $db = NewADOConnection("mysqli://root:@localhost/northwind");
00038         //$db->Connect('localhost','root','','test');
00039         break;
00040 }
00041 } catch (exception $e){
00042         echo "Connect Failed";
00043         adodb_pr($e);
00044         die();
00045 }
00046 
00047 $db->debug=1;
00048 
00049 $cnt = $db->GetOne("select count(*) from adoxyz where ?<id and id<?",array(10,20));
00050 $stmt = $db->Prepare("select * from adoxyz where ?<id and id<?");
00051 if (!$stmt) echo $db->ErrorMsg(),"\n";
00052 $rs = $db->Execute($stmt,array(10,20));
00053 
00054 echo  "<hr /> Foreach Iterator Test (rand=".rand().")<hr />";
00055 $i = 0;
00056 foreach($rs as $v) {
00057         $i += 1;
00058         echo "rec $i: "; $s1 = adodb_pr($v,true); $s2 = adodb_pr($rs->fields,true);
00059         if ($s1 != $s2 && !empty($v)) {adodb_pr($s1); adodb_pr($s2);}
00060         else echo "passed<br>";
00061         flush();
00062 }
00063 
00064 $rs = new ADORecordSet_empty();
00065 foreach($rs as $v) {
00066         echo "<p>empty ";var_dump($v);
00067 }
00068 
00069 
00070 if ($i != $cnt) die("actual cnt is $i, cnt should be $cnt\n");
00071 else echo "Count $i is correct<br>";
00072 
00073 $rs = $db->Execute("select bad from badder");
00074 
00075 } catch (exception $e) {
00076         adodb_pr($e);
00077         echo "<h3>adodb_backtrace:</h3>\n";
00078         $e = adodb_backtrace($e->gettrace());
00079 }
00080 
00081 $rs = $db->Execute("select distinct id, firstname,lastname from adoxyz order by id");
00082 echo "Result=\n",$rs,"</p>";
00083 
00084 echo "<h3>Active Record</h3>";
00085 
00086         include_once("../adodb-active-record.inc.php");
00087         ADOdb_Active_Record::SetDatabaseAdapter($db);
00088         
00089 try {
00090         class City extends ADOdb_Active_Record{};
00091         $a = new City();
00092 
00093 } catch(exception $e){
00094         echo $e->getMessage();
00095 }
00096 
00097 try {
00098         
00099         $a = new City();
00100         
00101         echo "<p>Successfully created City()<br>";
00102         #var_dump($a->GetPrimaryKeys());
00103         $a->city = 'Kuala Lumpur';
00104         $a->Save();
00105         $a->Update();
00106         #$a->SetPrimaryKeys(array('city'));     
00107         $a->country = "M'sia";
00108         $a->save();
00109         $a->Delete();
00110 } catch(exception $e){
00111         echo $e->getMessage();
00112 }
00113 
00114 //include_once("test-active-record.php");
00115 ?>