Documentation TYPO3 par Ameos

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


Généré par Les experts TYPO3 avec  doxygen 1.4.6