//写入缓存
$menu_query = exequery( $connection, " SELECT ct.id as tid, ct.type_name , mb.id, mb.cookname,
mb.price, mb.description, mb.pinyin FROM cook_type ct LEFT JOIN menubook mb ON ct.id = mb.cook_type WHERE
mb.id = ".$cook_id);
$menu_result = mysql_fetch_array( $menu_query );
//echo "菜单id:".$cook_id.";分类id:".$menu_result[tid];exit;
//本次菜单
$row[mid] = $cook_id;
$row[menu_name] = $cook_name;
$row[description] = $description;
$row[menu_price] = $cook_price;
$row[pinyin] = ChangeToPinyin(iconv("utf-8","gb2312",$cook_name),1);
if( file_exists( "./menubook.php") )
{
require_once( "./menubook.php" );
}
if( is_array( $menu_cache) && !empty( $menu_cache) )
{
$classnum = count( $menu_cache );
$unmatchnum = 0;
for ( $i=0; $i
{
if( $menu_result[tid] != $menu_cache[$i][tid] )
{
$unmatchnum++;
continue;
}
else //找到分类 , 继续寻找菜品的缓存是否存在
{
$cartenum = count( $menu_cache[$i][list]);
$unmarrynum = 0;
for ( $j=0; $j
{
if ( $menu_cache[$i][list][$j][mid] != $cook_id )
{
$unmarrynum++;
continue;
}
else //修改菜单
{
$menu_cache[$i][list][$j][menu_name] = $cook_name;
$menu_cache[$i][list][$j][description] = $description;
$menu_cache[$i][list][$j][menu_price] = $cook_price;
$menu_cache[$i][list][$j][pinyin] = $row[pinyin];
}
}
//新添加的菜单
if( $cartenum == $unmarrynum )
{
$menu_cache[$i][list][] = $row;
}
}
}
//未找到分类
if ( $unmatchnum == $classnum )
{
$type_row[tid] = $menu_result[tid];
$type_row[type_name] = $menu_result[type_name];
$type_row[list][0] = $row;
$menu_cache[] = $type_row;
}
}
else { //数组的生成
$type_row[tid] = $menu_result[tid];
$type_row[type_name] = $menu_result[type_name];
$type_row[list][0] = $row;
$menu_cache[] = $type_row;
}
//print_r( $menu_cache );
//写入文件
ob_start();
var_export( $menu_cache );
$content = ob_get_contents( );
ob_end_clean();
$filename = "menubook.php";
$fp = fopen( $filename, "w" );
fwrite( $fp, "" );
fclose( $fp );
二、添加菜单,写入缓存
$str=ChangeToPinyin(iconv("utf-8","gb2312",$cook_name),1);
$query_cook_add="insert into menubook(cookname,price,cook_type,description,pinyin) values(".$cook_name.",".$cook_price.",".$cook_type.",".$description.",".$str.")";
$cursor_cook_add=exequery($connection,$query_cook_add);
$cook_id = mysql_insert_id();
$menutype_query = exequery( $connection, " SELECT type_name FROM cook_type WHERE id = ".$cook_type);
$menutype_result = mysql_fetch_array( $menutype_query );
//本次菜单
$row[mid] = $cook_id;
$row[menu_name] = $cook_name;
$row[description] = $description;
$row[menu_price] = $cook_price;
$row[pinyin] = $str;
if( file_exists( "./menubook.php") )
{
require_once( "./menubook.php" );
}
if( is_array( $menu_cache) && !empty( $menu_cache) )
{
$classnum = count( $menu_cache );
$unmatchnum = 0;
for ( $i=0; $i
{
if( $cook_type != $menu_cache[$i][tid] )
{
$unmatchnum++;
continue;
}
else //找到分类 ,添加改产品菜品的缓存
{
$menu_cache[$i][list][] = $row;
}
}
if( $classnum == $unmatchnum ) //未找到分类
{
$type_row[tid] = $cook_type;
$type_row[type_name] = $menutype_result[type_name];
$type_row[list][0] = $row;
$menu_cache[] = $type_row;
}
}
else { //数组的生成
$type_row[tid] = $cook_type ;
$type_row[type_name] = $menutype_result[type_name];
$type_row[list][0] = $row;
$menu_c

aphpdepentioncontiveContainerIsatoolThatManagesClassDeptions,增强codemodocultion,可验证性和Maintainability.itactsasaceCentralHubForeatingingIndections,因此reducingTightCightTightCoupOulplingIndeSingantInting。

选择DependencyInjection(DI)用于大型应用,ServiceLocator适合小型项目或原型。1)DI通过构造函数注入依赖,提高代码的测试性和模块化。2)ServiceLocator通过中心注册获取服务,方便但可能导致代码耦合度增加。

phpapplicationscanbeoptimizedForsPeedAndeffificeby:1)启用cacheInphp.ini,2)使用preparedStatatementSwithPdoforDatabasequesies,3)3)替换loopswitharray_filtaray_filteraray_maparray_mapfordataprocrocessing,4)conformentnginxasaseproxy,5)

phpemailvalidation invoLvesthreesteps:1)格式化进行regulareXpressecthemailFormat; 2)dnsvalidationtoshethedomainhasavalidmxrecord; 3)

tomakephpapplicationsfaster,关注台词:1)useopcodeCachingLikeLikeLikeLikeLikePachetoStorePreciledScompiledScriptbyTecode.2)MinimimiedAtabaseSqueriSegrieSqueriSegeriSybysequeryCachingandeffeftExting.3)Leveragephp7 leveragephp7 leveragephp7 leveragephpphp7功能forbettercodeefficy.4)

到ImprovephPapplicationspeed,关注台词:1)启用opcodeCachingwithapCutoredUcescriptexecutiontime.2)实现databasequerycachingusingpdotominiminimizedatabasehits.3)usehttp/2tomultiplexrequlexrequestsandredececonnection.4 limitsclection.4.4

依赖注入(DI)通过显式传递依赖关系,显着提升了PHP代码的可测试性。 1)DI解耦类与具体实现,使测试和维护更灵活。 2)三种类型中,构造函数注入明确表达依赖,保持状态一致。 3)使用DI容器管理复杂依赖,提升代码质量和开发效率。

databasequeryOptimizationinphpinvolVolVOLVESEVERSEVERSTRATEMIESOENHANCEPERANCE.1)SELECTONLYNLYNESSERSAYCOLUMNSTORMONTOUMTOUNSOUDSATATATATATATATATATATRANSFER.3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

记事本++7.3.1
好用且免费的代码编辑器

WebStorm Mac版
好用的JavaScript开发工具

SublimeText3汉化版
中文版,非常好用

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。