function accessFail($debug) { global $scriptSuccess, $idOut, $scriptDebug; $scriptSuccess = False; $idOut = -1; $scriptDebug = $debug; scriptOutput(); die; } // Connect to the MySQL server process. //TODO: Use a .cnf file instead of hardcoding the MySQL login. mysql_connect('ix-trusty:3022', 'xunl', 'tbc123bl') or accessFail("Could not connect: " . mysql_error()); // Select the database containing address books. mysql_select_db($dbName) or accessFail("Could not find database: " . mysql_error()); // Test that the specified address book already exists. doesBookExist($bookName) or accessFail("Could not find address book: " . $bookName); // Branch: If there is an exact match, set id and go on to return; // If there is not, insert the row and get the new id. // If there is an exact match, return the id (arbitrarily picked if multiple). // Otherwise, return NULL. function getIdOfExactMatch($fn, $ln, $city, $st, $zip, $ph, $email, $addr1, $addr2, $bookName) { global $tableName; $sql = "SELECT * FROM {$tableName}\n WHERE first_name = '{$fn}' AND\n last_name = '{$ln}' AND\n city = '{$city}' AND\n state = '{$st}' AND\n zip = '{$zip}' AND\n phone = '{$ph}' AND\n email = '{$email}' AND\n address_1 = '{$addr1}' AND\n address_2 = '{$addr2}' AND\n address_book_ID = '{$bookName}' "; $queryResult = mysql_query($sql); if (mysql_num_rows($queryResult) > 0) { $row = mysql_fetch_assoc($queryResult); $id = $row['person_ID']; return $id; } else { return NULL;
<?php include_once '../utils.php'; $dbName = 'panda_address_book'; mysql_connect('ix-trusty:3022', 'xunl', 'tbc123bl') or accessFail("Could not connect: " . mysql_error()); mysql_select_db($dbName) or accessFail("Could not find database: " . mysql_error()); /* $tableName = 'book_names'; $sql = "SELECT * FROM $tableName"; // Select all, sorted. $queryResult = mysql_query($sql); while($row = mysql_fetch_assoc($queryResult)) { print_r($row); echo '<br>'; } */ echo doesBookExist('my friends') ? 'my friends' : 'stop 1'; echo '<br>'; echo doesBookExist('friends contacts') ? 'friends contacts' : 'stop 2'; echo '<br>'; echo touchBook('friends contacts') ? 'friends contacts' : 'stop 3'; mysql_close();