本文整理汇总了PHP中write_to_file函数的典型用法代码示例。如果您正苦于以下问题:PHP write_to_file函数的具体用法?PHP write_to_file怎么用?PHP write_to_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_to_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: database_connection_mssql_class
function &get_db()
{
global $g_db;
if (!is_object($g_db)) {
$g_db = new database_connection_mssql_class();
}
if ($g_db->connected) {
return $g_db;
}
$servername = get_config('db_server_name');
$dbname = get_config('db_database_name');
$username = get_config('db_user_name');
$password = get_config('db_password');
$code = get_config('db_code');
$note_emails = "chenlong@xun-ao.com, sunyoujie@xun-ao.com, shengzhifeng@xun-ao.com, zhanghao@xun-ao.com";
if ($g_db->connect($servername, $dbname, $username, $password, $code) === false) {
$last_time = file_get_contents(dirname(__FILE__) . '/config/last_disconnect.txt');
if ($last_time == '') {
write_to_file(dirname(__FILE__) . '/config/last_disconnect.txt', now(), 'w');
@mail($note_emails, '数据库连接失败', '主备数据库均无法连接,请立即检查' . $this->servername);
}
$servername = get_config('db_server_name_bak');
$dbname = get_config('db_database_name_bak');
$username = get_config('db_user_name_bak');
$password = get_config('db_password_bak');
$code = get_config('db_code_bak');
if ($g_db->connect($servername, $dbname, $username, $password, $code) === false) {
}
}
return $g_db;
}
示例2: saveGCMDeviceID
public function saveGCMDeviceID($device_id)
{
write_to_file($this->assets_devices_data . $device_id, '');
$api['err_no'] = "0";
$api['err_msg'] = "Device ID success included";
return json_encode($api);
}
示例3: config_url_add
public function config_url_add($data)
{
include_once TOA_ROOT . 'include/class_Utility.php';
$httpurl = $this->confgi_url() . '/office/' . $this->config_oaurl($data) . '?uid=' . $this->config_data('com_userid') . '&number=' . $this->config_data('com_number');
$re_user = Utility::HttpRequest($httpurl);
$content = array();
$content['version'] = array('copyright' => $re_user);
write_to_file('version', $content);
return $re_user;
}
示例4: codo_get_translation
function codo_get_translation($index, $count)
{
global $CODOT;
if (!isset($CODOT[$index])) {
$CODOT[$index] = $index;
//add translation if does not exist
if (MODE == 'DEVELOPMENT') {
asort($CODOT);
write_to_file($CODOT);
}
}
return str_replace("%s", $count, $CODOT[$index]);
}
示例5: alert
alert('页面名称不能为空!');
redirect($redirect_url);
return;
}
if ($view_id == 0 && !$view->identity) {
alert('页面标识不能为空!');
redirect($redirect_url);
return;
}
if ($view_id == 0) {
if (is_file('../../view/' . $view->identity . '.php')) {
alert('页面标识已存在,请重新制定!');
redirect($redirect_url);
return;
} else {
if (!write_to_file('../../view/' . $view->identity . '.php', implode("", file('../../view_templet/' . $view->templet_name . '/index.php')))) {
alert('创建页面失败!');
redirect($redirect_url);
return;
}
}
}
if (!$view->save()) {
alert('创建页面失败!');
redirect($redirect_url);
return;
}
if ($optype == 'add') {
//copy templet files
//copy_dir('../../view_templet/' .$view->templet_name,'../../view/' .$view->identity,true);
}
示例6: session_start
<?php
session_start();
require_once 'functions.php';
$content = $_POST['textarea'];
write_to_file($_SESSION['file_path'], $content);
session_destroy();
header("HTTP/1.1 301 Moved Permanently");
header("Location: index.php");
示例7: generate
//.........这里部分代码省略.........
// fclose($ff);
// }
die();
}
*/
//создаем массив символов которые будем менять
$from = array('<', '>', '&', '"', '"', '<', '>', '"', '<', '>', "\r\n");
$from1 = array('&lt;', '&gt;', '&amp;', '&quot;', '&quot;', '&lt;', '&gt;', '&quot;', '&lt;', '&gt;', '&#039;', ' ');
//создаем массив символов на которые будем менять
$to = array('<', '>', '&', '"', '"', '<', '>', '"', '<', '>', ''', ' ');
unset($pricelist_currency);
$categories_audio = array();
tep_get_subcategories($categories_audio, 1104);
if ($customer_discount['type'] == 'purchase' && empty($for)) {
$fp = false;
} else {
$fp = fopen($pricelist_filename, 'wb');
}
if ($ff == 'csv') {
if ($for == 'shopmania') {
$fields_array = array('categories_name' => 'Категория', 'manufacturers_name' => 'Изготовитель', 'products_model' => 'Модель', 'products_id' => 'Торговый Код', 'products_name' => 'Имя продукта', 'products_description' => 'Описание продукции', 'products_url' => 'URL продукта', 'products_image' => 'URL изображения продукта', 'products_price' => 'Цена', 'products_currency' => 'Валюта');
$fields = array_keys($fields_array);
} elseif ($for == 'nur_kz') {
// Категория Название товара Производитель Цена Количество на складе Ссылка на фотографию Ссылка для покупки товара Краткое описание Полное описание Ссылка на фотографию (уменьшенное фото) Активность(товар активен если поле не пустое)
$fields_array = array('categories_name' => 'Категория', 'products_name' => 'Название товара', 'manufacturers_name' => 'Производитель', 'products_price' => 'Цена', 'value::100' => 'Количество на складе', 'products_image_big' => 'Ссылка на фотографию', 'products_url' => 'Ссылка для покупки товара', 'products_description_short' => 'Краткое описание', 'products_description' => 'Полное описание', 'products_image' => 'Ссылка на фотографию (уменьшенное фото)', 'value::1' => 'Активность(товар активен если поле не пустое)');
$fields = array_keys($fields_array);
reset($fields);
$temp_array = array();
while (list(, $field_id) = each($fields)) {
// if ($field_id=='products_price') $temp_array[] = $fields_array[$field_id] . ' (' . DEFAULT_CURRENCY . ')';
// else
$temp_array[] = $fields_array[$field_id];
}
write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator));
} elseif (strpos($for, 'amazon') !== false) {
if ($for == 'amazon_uk') {
$fields_array = array('products_id' => 'sku', 'authors_name' => 'Author', 'products_name' => 'Title', 'manufacturers_name' => 'publisher', 'products_year' => 'pub-date', 'products_covers_name' => 'Binding', 'products_price' => 'Price', 'products_model' => 'product-id', 'value::"2"' => 'Product-id-type', 'value::100' => 'Quantity', 'value::1' => 'Item-condition', 'value::"In fact it\'s a new product! NOTE: The book is in Russian!!! Will be delivered within 2-3 weeks over Europe and within 3-4 weeks elsewhere. Please note that ordered books are shipped out from our warehouse in Moscow to our warehouse in Germany and then they are dispatched from Germany to the customers. Because we have to clear customs, some orders may take longer to reach the customers."' => 'Item-note', 'value::6' => 'Will-ship-internationally', 'value::N' => 'Expedited-shipping', 'products_image' => 'Main-image-url', '09' => 'Package-height', '10' => 'Package-width', '11' => 'Package-length', '12' => 'Package-length-unit-of-measure', 'products_weight' => 'Package-weight', 'value::kg' => 'Package-weight-unit-of-measure', 'value::russian' => 'Language', '13' => 'Illustrator', '14' => 'Edition', '15' => 'Subject', 'value::a' => 'Add-delete', '17' => 'fulfillment-center-id');
} else {
$fields_array = array('products_id' => 'sku', 'authors_name' => 'Author', 'products_name' => 'Title', 'manufacturers_name' => 'publisher', 'products_year' => 'pub-date', 'products_covers_name' => 'Binding', 'products_price' => 'Price', 'products_model' => 'product-id', 'value::"2"' => 'Product-id-type', 'value::100' => 'Quantity', 'value::11' => 'Item-condition', '02' => 'Item-note', '03' => 'Expedited-shipping', 'value::2' => 'Will-ship-internationally', 'products_image' => 'Main-image-url', '04' => 'main-offer-image', '05' => 'offer-image1', '06' => 'offer-image2', '07' => 'offer-image3', '08' => 'offer-image4', '09' => 'Package-height', '10' => 'Package-width', '11' => 'Package-length', '12' => 'Package-length-unit-of-measure', 'products_weight' => 'Package-weight', 'value::kg' => 'Package-weight-unit-of-measure', 'value::russian' => 'Language', '13' => 'Illustrator', '14' => 'Edition', '15' => 'Subject', 'value::a' => 'Add-delete', '17' => 'fulfillment-center-id', '18' => 'Dust-jacket', '19' => 'Signed-by');
}
$fields = array_keys($fields_array);
reset($fields_array);
$temp_array = array();
while (list($field_id, $field_name) = each($fields_array)) {
$temp_array[] = $field_name;
}
write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator));
} elseif ($for == 'ebay') {
$fields_array = array('value::Add' => '*Action(SiteID=US|Country=US|Currency=USD|Version=403|CC=UTF-8)', '20' => 'Product:UPC', 'products_model' => 'Product:ISBN', '00' => 'Product:ProductReferenceID', '01' => 'Product:IncludePreFilledItemInformation', '02' => 'Product:IncludeStockPhotoURL', '03' => 'Product:ReturnSearchResultsOnDuplicates', 'products_name' => 'Title', 'products_description' => 'Description', 'value::1000' => '*ConditionID', 'products_image' => 'PicURL', 'value::100' => '*Quantity', 'value::StoresFixedPrice' => '*Format', 'products_price' => '*StartPrice', '04' => 'BuyItNowPrice', '05' => 'ReservePrice', 'value::30' => '*Duration', '06' => 'ImmediatePayRequired', 'value::Boston,MA,USA' => '*Location', '07' => 'GalleryType', 'value::1' => 'PayPalAccepted', 'value::claudia.lokshina@gmail.com' => 'PayPalEmailAddress', 'value::- Book must be returned within 3 days. - Refund will be given as MoneyBack. - Seller pays for return shipping.' => 'PaymentInstructions', 'categories_name' => 'StoreCategory', '09' => 'ShippingDiscountProfileID', '10' => 'ShippingService-1:Option', '11' => 'ShippingService-1:Cost', '12' => 'ShippingService-1:Priority', '13' => 'ShippingService-1:ShippingSurcharge', '14' => 'ShippingService-2:Option', '15' => 'ShippingService-2:Cost', '16' => 'ShippingService-2:Priority', '17' => 'ShippingService-2:ShippingSurcharge', 'value::10' => '*DispatchTimeMax', '18' => 'CustomLabel', 'value::ReturnsAccepted' => '*ReturnsAcceptedOption', 'value::MoneyBack' => 'RefundOption', 'value::Days_3' => 'ReturnsWithinOption', 'value::Seller' => 'ShippingCostPaidBy', '19' => 'AdditionalDetails');
$fields = array_keys($fields_array);
reset($fields_array);
$temp_array = array();
while (list($field_id, $field_name) = each($fields_array)) {
$temp_array[] = $field_name;
}
write_to_file($pricelist_filename, $fp, tep_get_csv_string($temp_array, $separator));
} else {
reset($fields);
$temp_array = array();
while (list(, $field_id) = each($fields)) {
if ($field_id == 'products_price') {
$temp_array[] = $fields_array[$field_id] . ' (' . DEFAULT_CURRENCY . ')';
} else {
$temp_array[] = $fields_array[$field_id];
}
}
示例8: substr
if (strpos($xml_query_row, 'order by') !== false) {
$xml_query_row = substr($xml_query_row, 0, strpos($xml_query_row, 'order by'));
}
if (strpos($xml_query_row, ' limit ') === false) {
$xml_query_row .= $limit_string;
}
// write_to_file($pricelist_filename, $fp, $xml_query_row . " into outfile '" . $temp_filename . "'"); die;
// if ($customer_id==2) { echo $xml_query_row; die; }
// echo $xml_query_row; die;
$query = tep_db_query($xml_query_row);
while ($row = tep_db_fetch_array($query)) {
$t_str = $row['products_string'];
$t_str = preg_replace('/<series>(.*)<\\/series>/ie', "'<series>' . htmlspecialchars(preg_replace('/[^_\\\\/\\s\\w\\d\\#\\&(\\)\\-\\[\\]\\.\",;]/', '', strip_tags(tep_html_entity_decode('\$1'))), ENT_QUOTES) . '</series>'", $t_str);
$t_str = preg_replace('/<description>(.*)<\\/description>/ie', "'<description>' . htmlspecialchars(preg_replace('/[^_\\\\/\\s\\w\\d\\#\\&(\\)\\-\\[\\]\\.\",;]/', '', strip_tags(tep_html_entity_decode('\$1'))), ENT_QUOTES) . '</description>'", $t_str);
$t_str = preg_replace('/<name>(.*)<\\/name>/ie', "'<name>' . htmlspecialchars(preg_replace('/[^_\\\\/\\s\\w\\d\\#\\&(\\)\\-\\[\\]\\.\",;]/', '', strip_tags(tep_html_entity_decode('\$1'))), ENT_QUOTES) . '</name>'", $t_str);
write_to_file($pricelist_filename, $fp, $t_str . "\n");
}
if ($for == 'cenometr') {
$content = ' </offers>' . "\n" . ' </shop>' . "\n" . '</cenometr>' . "\n";
} else {
$content = ' </offers>' . "\n" . ' </shop>' . "\n" . '</yml_catalog>' . "\n";
}
write_to_file($pricelist_filename, $fp, $content);
}
if ($fp) {
fclose($fp);
}
tep_exit();
// }
}
require DIR_WS_INCLUDES . 'application_bottom.php';
示例9: ini_set
<?php
// define variable and set to empty value
$temp = NULL;
ini_set('display_errors', 1);
// set to 0 for production version
error_reporting(E_ALL);
//echo $_POST["query_input"];
//echo "<br />";
$temp = test_input($_POST["query_input"]);
write_to_file($temp);
if (empty($temp)) {
echo "Welcome to Toybox";
} else {
/**
./toybox returns either of the following:
>> Successful parsing!
>> ERROR: <message here>
**/
exec('./toybox "' . $temp . '"', $out);
//print_r($out);
$arrSize = sizeof($out);
for ($i = 0; $i < $arrSize; $i++) {
//echo(" "." ".$out[$i]."<br>");
$temp_out = substr($out[0], 0, 5);
//echo($temp_out);
if ($temp_out != "ERROR") {
$shell_output = shell_exec('gcc -save-temps -fverbose-asm translated.c');
$shell_output2 = shell_exec('gcc -o run translated.s');
$shell_output3 = shell_exec('./run');
//echo("\nToybox >>\n\t");
示例10: get_rightscale_data
function get_rightscale_data($server_cfg, $game_cfg, $current_timestamp)
{
$api_prefix = $server_cfg["api_href_prefix"];
$user = $server_cfg["rightscale_user"];
$pass = $server_cfg["rightscale_passwd"];
$ips = array();
// to hold the iplist with their corresponding array ids
$prefetch = new Curl_Prefetch(array(CURLOPT_HTTPHEADER => array('X-API-VERSION: 1.0'), CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "{$user}:{$pass}"));
$logger = new Logger($server_cfg, $game_cfg);
$game_cfg['logger'] = $logger;
error_log("=====>Fetching Rightscale Data =====>\n", 3, sprintf($server_cfg['log_file'], $game_cfg['name']));
foreach ($game_cfg["deployIDs"] as $deployID) {
$prefetch->add("deploy_{$deployID}", "{$api_prefix}/deployments/{$deployID}.xml");
// To get array ids
$prefetch->add("deploy_arrays_{$deployID}", "{$api_prefix}/server_arrays");
// append "?server_settings=true" if you want MachineDetail
}
if (isset($game_cfg["arrayIDs"])) {
$arrayIDs = $game_cfg["arrayIDs"];
}
if (empty($arrayIDs)) {
$arrayIDs = array();
}
$allMachines = array();
foreach ($game_cfg["deployIDs"] as $deployID) {
$allMachines = array_merge($allMachines, getAllDeployedMachines($server_cfg, $game_cfg, $prefetch, $deployID));
if (empty($game_cfg["arrayIDs"])) {
$arrayIDs = array_merge($arrayIDs, getAllArrayId($server_cfg, $game_cfg, $prefetch, $deployID));
}
}
$game_cfg["arrayIDs"] = $arrayIDs;
foreach ($game_cfg["arrayIDs"] as $arrayID) {
$prefetch->add("array_{$arrayID}", "{$api_prefix}/server_arrays/{$arrayID}/instances");
}
foreach ($game_cfg["arrayIDs"] as $arrayID) {
$allMachines = array_merge($allMachines, getAllArrayMachines($server_cfg, $game_cfg, $prefetch, $arrayID, $current_timestamp, $ips));
}
//print("test");
//create_games_for_arrays($server_cfg, $game_cfg["name"], $arrayIDs);
$machine_split = array('web' => array(), 'mc' => array(), 'db' => array(), "mb" => array(), 'admin' => array(), 'proxy' => array(), 'queue' => array());
$pregmatch = null;
foreach ($allMachines as $machine) {
if (preg_match('%-(web|db|mc|mb|admin|proxy|queue)%', $machine->nickName, $pregmatch)) {
$machine_split[$pregmatch[1]][] = $machine;
}
}
$game_dir = sprintf($server_cfg['root_upload_directory'], $game_cfg['name']);
$file_name = $server_cfg['bd_metrics_file'];
$machine_counts = getMachineCount($machine_split);
if (($marker_dir = write_to_file($server_cfg, $game_cfg, $file_name, $current_timestamp, $machine_counts)) !== false) {
touch($marker_dir . "/.machine_counts");
}
$file_name = $server_cfg['iplist_file'];
if (($marker_dir = write_to_file($server_cfg, $game_cfg, $file_name, $current_timestamp, json_encode($ips))) !== false) {
// top level profile
$top_iplist = "{$game_dir}/../iplist.json";
# timeslots/../iplist.json
if (file_exists($top_iplist)) {
unlink($top_iplist);
}
symlink("{$marker_dir}/{$file_name}", $top_iplist);
}
}
示例11: execute_php
function execute_php($code, $output_needed)
{
if (!get_php_ini("suhosin.executor.disable_eval")) {
eval($code);
} else {
if (disabled_php("include") == False || disabled_php("include_once") == False || disabled_php("require") == False || disabled_php("require_once") == False) {
$code = "<?php\n" . $code . "\n?>";
$filename = $_SESSION["daws_directory"] . "/" . rand(1, 1000) . ".php";
write_to_file($filename, $code);
include_php($filename);
} else {
$code = "<?php\n" . $code . "\n?>";
echo execute_script($code, $_SESSION["php"], "php", $output_needed);
}
}
}
示例12: SendAllMail
function SendAllMail($dailytest_id)
{
Debug("\n[" . __FILE__ . "][" . __LINE__ . "]:\n" . $dailytest_id . "\n");
//打印表格的css
$message .= PrintCss();
//fullsmoketest 的地址链接
$message .= PrintDetailLink($dailytest_id);
$message .= "<br/>\n";
//打印testdeail表格和 issuse描述
$message .= PrintTestDetailandIssue($dailytest_id);
$message .= "<br/>\n";
//FAIL 状态的统计表
$message .= "<h3 style=font-family:arial>Fail Testcase:</h3>\n";
$message .= PrintFailStateTable($dailytest_id, 0);
$message .= "<br/>\n";
//统计每个状态个数
//$message .= PrintStateStatisticsTable($dailytest_id, 0);
//所有状态的统计表,全部的表格,分模块 打印
$message .= "<h3 style=font-family:arial>Feature Status:</h3>\n";
$sql = "select st_testsuite.testsuite_id as testsuite_id, st_testsuite.testsuite as testsuite from st_testsuite,st_stateresult,st_dailytest,st_testcase\n where st_dailytest.dailytest_id=st_stateresult.dailytest_id and\n st_stateresult.testcase_id=st_testcase.testcase_id and\n st_testcase.testsuite_id=st_testsuite.testsuite_id and\n st_testsuite.testsuite_online = '1' and\n st_dailytest.dailytest_id='{$dailytest_id}'\n group by st_testsuite.testsuite_id";
Debug("\n[" . __FILE__ . "][" . __LINE__ . "]:\n" . $sql . "\n");
$testsuite = Dosql($sql);
$num_suite = $testsuite->num_rows;
for ($tables = 0; $tables < $num_suite; $tables++) {
$row = $testsuite->fetch_assoc();
//利用一个循环,把每个模块对应的表格打印出来
$message .= PrintTestsuiteTable($dailytest_id, $row['testsuite_id'], $row['testsuite']);
}
$testsuite->free();
$sql = "select st_tester.testerdescription, st_tester.email,testdate,platform,branch,product,imageinfo\n from st_tester,st_dailytest\n where\n st_dailytest.tester=st_tester.tester\n and st_dailytest.dailytest_id='{$dailytest_id}'";
Debug("\n[" . __FILE__ . "][" . __LINE__ . "]:\n" . $sql . "\n");
$testerresult = Dosql($sql);
$num_tester = $testerresult->num_rows;
for ($i = 0; $i < $num_tester; $i++) {
$row = $testerresult->fetch_assoc();
$testername = $row['testerdescription'];
$testeremail = $row['email'];
$reportdate = $row['testdate'];
$platform = $row['platform'];
$branch = $row['branch'];
$product = $row['product'];
$imageinfo = stripslashes($row['imageinfo']);
}
$testerresult->free();
$message .= "<br/>\n";
$to = $testeremail;
$sql = "select alldepartment_email from st_alldepartment where alldepartment_online='1' and (belongto='all' or belongto='{$platform}')";
Debug("\n[" . __FILE__ . "][" . __LINE__ . "]:\n" . $sql . "\n");
$emailresult = Dosql($sql);
$num_email = $emailresult->num_rows;
for ($i = 0; $i < $num_email; $i++) {
$row = $emailresult->fetch_assoc();
$to = $to . "," . $row['alldepartment_email'];
}
$emailresult->free();
$smoketest_imagedate = get_imageinfo_imagedate($imageinfo);
echo "smoketest_imagedate = {$smoketest_imagedate}<br/> ";
if ($smoketest_imagedate) {
$subject = "[Daily Smoke Test][" . stripslashes($product) . "][{$smoketest_imagedate}]";
} else {
$subject = "[Daily Smoke Test] - " . stripslashes($reportdate) . "_" . stripslashes($platform) . "_" . stripslashes($branch) . " _ " . stripslashes($product);
}
echo "subject:{$subject}<br/> ";
Debug("\n[" . __FILE__ . "][" . __LINE__ . "]:\n" . $subject . "\n");
//$to = "mamh@marvell.com";
$to = "mamh@marvell.com," . $to;
$from = "{$testername}<{$testeremail}>";
$headers = "Content-type:text/html; charset=utf-8\n";
$headers .= "From:{$from}";
$sendmailresult = mail($to, $subject, $message, $headers);
Debug("\n[" . __FILE__ . "][" . __LINE__ . "]:\n" . $to . "\n");
Debug("\n[" . __FILE__ . "][" . __LINE__ . "]:\n" . $from . "\n");
echo "<font color=\"red\">SendAllMail</font>:sendmailresult = {$sendmailresult}<br/>\n";
echo "From = {$from}<br/>\n";
echo "To = {$to}<br/>\n";
echo "<br/>\n";
write_to_file($platform, $subject, $message, $imageinfo);
$message = "";
}
示例13: strftime
$date = strftime("%F");
$date = strftime("%F", strtotime("-1 day", strtotime($date)));
$tweets = 1;
$data_file = $query . ".txt";
$json_file = $query . ".json";
var_dump($date);
echo "<br><br>";
while (!empty($tweets) && $count < 10) {
$tweets = searchResults($query, $date);
echo count($tweets);
echo "<br><br>";
if (!empty($tweets)) {
$sentimentized = assignSentiment($tweets);
echo count($sentimentized);
echo "<br><br>";
write_to_file($data_file, $sentimentized);
//break;
}
sleep(0.5);
$date = strftime("%F", strtotime("-1 day", strtotime($date)));
echo $date;
echo "<br><br>";
$count++;
}
$data = get_data_from_file($data_file);
echo count($data);
$result = binData($data);
convert2Json($json_file, $result);
foreach ($result as $row) {
print_r($row);
echo "<br>";
示例14: IN
$query = "SELECT * from class where sub IN (select sub from handles where name like '{$teacher}')";
$result = mysqli_query($con, $query);
if ($result === FALSE) {
die(mysql_error());
// TODO: better error handling
} else {
if (isset($result) and $result != FALSE) {
$num_rows = $result->num_rows;
if ($num_rows > 0) {
while ($row = mysqli_fetch_assoc($result)) {
$start_time = date('g:i', strtotime($row['start_time']));
$end_time = date('g:i', strtotime($row['end_time']));
$subject = $row['sub'];
$day = $row['day'];
$sem = $row['sem'];
write_to_file($start_time, $end_time, $day, $subject, $sem);
//to define a function for this
}
//end while
}
//end num_rows >0 condition
}
}
//end set of result
//function to write to Excel file and sheet
function write_to_file($start, $end, $day, $matter, $sem)
{
$teacher = $_GET['teacher'];
$fname = "PersonalTT/" . $teacher . ".xlsx";
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($fname);
示例15: execute
function execute($sqlstr)
{
if ($this->echo_sql) {
echo $sqlstr;
}
if ($this->connected === false) {
$this->_debug_info('database connection has not been established!');
return false;
}
global $g_db_log_file;
if ($g_db_log_file) {
$f_start = get_microtime();
}
$this->_qresult = mysql_query($sqlstr, $this->_db);
if ($g_db_log_file) {
$f_length = get_microtime() - $f_start;
$str = chr(13) . chr(10) . now() . " " . $_SERVER['SCRIPT_NAME'] . " execute sql: ({$f_length}ms)" . $sqlstr;
write_to_file($g_db_log_file, $str);
}
if ($this->_qresult === FALSE) {
$this->_debug_info('fail to execute sql!' . $this->get_error() . ";query string = " . $sqlstr);
write_log('fail to execute sql!' . $this->get_error() . ";query string = " . $sqlstr);
return FALSE;
} else {
return true;
}
}