fixed typo in security checks for prescription access
[openemr.git] / library / adodb / tests / test4.php
blob64fb8b01a07867ca4dcf1ff7f500fedab79fc2d1
1 <?php
3 /**
4 * @version V4.20 22 Feb 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
5 * Released under both BSD license and Lesser GPL library license.
6 * Whenever there is any discrepancy between the two licenses,
7 * the BSD license will take precedence.
9 * Set tabs to 4 for best viewing.
11 * Latest version is available at http://php.weblogs.com
13 * Test GetUpdateSQL and GetInsertSQL.
16 error_reporting(E_ALL);
17 function testsql()
20 //define('ADODB_FORCE_NULLS',1);
22 include('../adodb.inc.php');
23 include('../tohtml.inc.php');
25 //==========================
26 // This code tests an insert
28 $sql = "
29 SELECT *
30 FROM ADOXYZ WHERE id = -1";
31 // Select an empty record from the database
33 $conn = &ADONewConnection("mysql"); // create a connection
34 //$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
36 $conn->debug=1;
37 $conn->PConnect("localhost", "root", "", "test"); // connect to MySQL, testdb
38 $conn->Execute("delete from adoxyz where lastname like 'Smith%'");
40 $rs = $conn->Execute($sql); // Execute the query and get the empty recordset
41 $record = array(); // Initialize an array to hold the record data to insert
43 // Set the values for the fields in the record
44 $record["firstname"] = 'null';
45 $record["lastname"] = "Smith\$@//";
46 $record["created"] = time();
47 //$record["id"] = -1;
49 // Pass the empty recordset and the array containing the data to insert
50 // into the GetInsertSQL function. The function will process the data and return
51 // a fully formatted insert sql statement.
52 $insertSQL = $conn->GetInsertSQL($rs, $record);
54 $conn->Execute($insertSQL); // Insert the record into the database
56 //==========================
57 // This code tests an update
59 $sql = "
60 SELECT *
61 FROM ADOXYZ WHERE lastname=".$conn->qstr($record['lastname']);
62 // Select a record to update
64 $rs = $conn->Execute($sql); // Execute the query and get the existing record to update
65 if (!$rs) print "<p>No record found!</p>";
67 $record = array(); // Initialize an array to hold the record data to update
69 // Set the values for the fields in the record
70 $record["firstName"] = "Caroline".rand();
71 $record["lasTname"] = "Smithy Jones"; // Update Caroline's lastname from Miranda to Smith
72 $record["creAted"] = '2002-12-'.(rand()%30+1);
73 $record['num'] = 3921;
74 // Pass the single record recordset and the array containing the data to update
75 // into the GetUpdateSQL function. The function will process the data and return
76 // a fully formatted update sql statement.
77 // If the data has not changed, no recordset is returned
78 $updateSQL = $conn->GetUpdateSQL($rs, $record);
80 $conn->Execute($updateSQL); // Update the record in the database
81 print "<p>Rows Affected=".$conn->Affected_Rows()."</p>";
83 $rs = $conn->Execute("select * from adoxyz where lastname like 'Smith%'");
84 adodb_pr($rs);
85 rs2html($rs);
89 testsql();