php连接mysql查询一条数据
数据库中有张表有主键pmcode还有其他属性如图:
我现在想通过pmcode判断某个用户是否存在,存在的话将其信息取出,不存在的话返回"不存在",然后通过拼接xml的形式发送出去,代码如下:
//拆分发来的信息得到会员卡号<br /> $arry=explode("+",$form_Content);<br /> $memberid =$arry[1];<br /> <br /> //连接数据库<br /> $link=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);<br /> if($link) {<br /> mysql_select_db(SAE_MYSQL_DB,$link); <br /> //查询数据<br /> $result1=mysql_query("select * from numbers where pmcode = '".$memberid."';");<br /> <br /> $num_result = mysql_num_rows($result1);<br /> if($num_result==1){<br /> // $row= $result1->fetch_assoc();<br /> $row=mysql_fetch_row($result1);<br /> $result_str="您的会员--信息如下:\n\n卡号:$row[pmcode].\n姓名:.$row[names].\n等级:.$row[4].\n积分:$a[5]";<br /> $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType,$result_str); <br /> echo $resultStr; <br /> exit;<br /> }else{<br /> $msgType = "text";<br /> $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType,"--select * from numbers where pmcode = '".$memberid."'"); <br /> echo $resultStr; <br /> exit;<br /> <br /> }<br /> <br /> } else{<br /> echo "连接数据库失败".mysql_error;<br /> } <br /> mysql_close($link);<br /> }
可是就算输入正确的pmcode都娶不到想要的数据,求大神修改

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools
