"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/adodb/adodb/tests/test4.php Source File", "datetime" => "Sat Dec 2 19:22:27 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

test4.php

00001 <?php
00002 
00016 error_reporting(E_ALL);
00017 function testsql()
00018 {
00019 
00020 
00021 include('../adodb.inc.php');
00022 include('../tohtml.inc.php');
00023 
00024 global $ADODB_FORCE_TYPE;
00025 
00026 
00027 //==========================
00028 // This code tests an insert
00029 
00030 $sql = "
00031 SELECT * 
00032 FROM ADOXYZ WHERE id = -1"; 
00033 // Select an empty record from the database 
00034 
00035 
00036 #$conn = &ADONewConnection("mssql");  // create a connection
00037 #$conn->PConnect("", "sa", "natsoft", "northwind"); // connect to MySQL, testdb
00038 
00039 $conn = &ADONewConnection("mysql");  // create a connection
00040 $conn->PConnect("localhost", "root", "", "test"); // connect to MySQL, testdb
00041 
00042 $conn =& ADONewConnection('oci8po');
00043 $conn->Connect('','scott','natsoft');
00044 //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
00045 
00046 $conn->debug=1;
00047 $conn->Execute("delete from adoxyz where lastname like 'Smi%'");
00048 
00049 $rs = $conn->Execute($sql); // Execute the query and get the empty recordset
00050 $record = array(); // Initialize an array to hold the record data to insert
00051 
00052 if (strpos($conn->databaseType,'mysql')===false) $record['id'] = 751;
00053 $record["firstname"] = 'Jann';
00054 $record["lastname"] = "Smitts";
00055 $record["created"] = time();
00056 
00057 $insertSQL = $conn->GetInsertSQL($rs, $record);
00058 $conn->Execute($insertSQL); // Insert the record into the database
00059 
00060 if (strpos($conn->databaseType,'mysql')===false) $record['id'] = 752;
00061 // Set the values for the fields in the record
00062 $record["firstname"] = 'anull';
00063 $record["lastname"] = "Smith\$@//";
00064 $record["created"] = time();
00065 
00066 if (isset($_GET['f'])) $ADODB_FORCE_TYPE = $_GET['f'];
00067 
00068 //$record["id"] = -1;
00069 
00070 // Pass the empty recordset and the array containing the data to insert
00071 // into the GetInsertSQL function. The function will process the data and return
00072 // a fully formatted insert sql statement.
00073 $insertSQL = $conn->GetInsertSQL($rs, $record);
00074 $conn->Execute($insertSQL); // Insert the record into the database
00075 
00076 
00077 
00078 $insertSQL2 = $conn->GetInsertSQL($table='ADOXYZ', $record);
00079 if ($insertSQL != $insertSQL2) echo "<p><b>Walt's new stuff failed</b>: $insertSQL2</p>";
00080 //==========================
00081 // This code tests an update
00082 
00083 $sql = "
00084 SELECT * 
00085 FROM ADOXYZ WHERE lastname=".$conn->Param('var'). " ORDER BY 1"; 
00086 // Select a record to update 
00087 
00088 $varr = array('var'=>$record['lastname'].'');
00089 $rs = $conn->Execute($sql,$varr); // Execute the query and get the existing record to update
00090 if (!$rs || $rs->EOF) print "<p><b>No record found!</b></p>";
00091 
00092 $record = array(); // Initialize an array to hold the record data to update
00093 
00094 
00095 // Set the values for the fields in the record
00096 $record["firstName"] = "Caroline".rand();
00097 //$record["lasTname"] = ""; // Update Caroline's lastname from Miranda to Smith
00098 $record["creAted"] = '2002-12-'.(rand()%30+1);
00099 $record['num'] = '';
00100 // Pass the single record recordset and the array containing the data to update
00101 // into the GetUpdateSQL function. The function will process the data and return
00102 // a fully formatted update sql statement.
00103 // If the data has not changed, no recordset is returned
00104 
00105 $updateSQL = $conn->GetUpdateSQL($rs, $record);
00106 $conn->Execute($updateSQL,$varr); // Update the record in the database
00107 if ($conn->Affected_Rows() != 1)print "<p><b>Error1 </b>: Rows Affected=".$conn->Affected_Rows().", should be 1</p>";
00108 
00109 $record["firstName"] = "Caroline".rand();
00110 $record["lasTname"] = "Smithy Jones"; // Update Caroline's lastname from Miranda to Smith
00111 $record["creAted"] = '2002-12-'.(rand()%30+1);
00112 $record['num'] = 331;
00113 $updateSQL = $conn->GetUpdateSQL($rs, $record);
00114 $conn->Execute($updateSQL,$varr); // Update the record in the database
00115 if ($conn->Affected_Rows() != 1)print "<p><b>Error 2</b>: Rows Affected=".$conn->Affected_Rows().", should be 1</p>";
00116 
00117 $rs = $conn->Execute("select * from ADOXYZ where lastname like 'Sm%'");
00118 //adodb_pr($rs);
00119 rs2html($rs);
00120 
00121 $record["firstName"] = "Carol-new-".rand();
00122 $record["lasTname"] = "Smithy"; // Update Caroline's lastname from Miranda to Smith
00123 $record["creAted"] = '2002-12-'.(rand()%30+1);
00124 $record['num'] = 331;
00125 
00126 $conn->AutoExecute('ADOXYZ',$record,'UPDATE', "lastname like 'Sm%'");
00127 $rs = $conn->Execute("select * from ADOXYZ where lastname like 'Sm%'");
00128 //adodb_pr($rs);
00129 rs2html($rs);
00130 }
00131 
00132 
00133 testsql();
00134 ?>