search

我的php版本是5.4的,MYsql_query对应到sqlserver中应该是什么呢,是mssql_query吗,为什么会报“mssql_query没有被定义”的错误呢?


回复讨论(解决方案)

没有加载mssql的php扩展

找到php.ini中的
;extension=php_mssql.dll
改成
extension=php_mssql.dll

然后重启apache

没有加载mssql的php扩展

找到php.ini中的
;extension=php_mssql.dll
改成
extension=php_mssql.dll

然后重启apache



这个已经改过了啊,我还加入了php_pdo_sqlsrv_54_ts和php_sqlsrv_54_ts两个扩展库,我连接数据库时是用的pdo连接的sqlserver数据库:$conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); 
是不是我用PDO连接的数据库,所以用mssql_query就无法使用呢?(新手上来就用sqlserver,很多东西不明白啊)

sqlsrv_query

sqlsrv_query


多谢回复!你说的这个方法确实可以,我的代码如下,可为什么插入失败呢?
是语法有问题还是其他的问题呢,继续请教啊
   header("Content-type:text/html;charset=utf-8");
   $serverName = "192.168.1.122,1433"; 
   $database = "hr";
   $uid = "sa";
   $pwd = "awefff;
   $connstr = array("Database"=>"$database","Uid"=>"$uid","Pwd"=>"$pwd","CharacterSet" => "UTF-8");
   try {
      //$conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); 
  $conn = sqlsrv_connect( "$serverName",$connstr);
  if( $conn ) {
     echo "Connection established.
";
     }else{
     echo "Connection could not be established.
";
     die( print_r( sqlsrv_errors(), true));
}
   }

   catch( PDOException $e ) {
      die( "Error connecting to SQL Server".$e ); 
   }
    $bmtx=$_POST['bmtx'];
    $gzbm=$_POST['gzbm'];
    $bsc=$_POST['bsc'];
    $gwmc=$_POST['gwmc'];
    $zwzj=$_POST['zwzj'];
$zwcj=$_POST['zwcj'];
$zx=$_POST['zx'];
$ygbh=$_POST['ygbh'];
$ygxm=$_POST['ygxm'];
$sSex=$_POST['sSex'];
echo $bmtx;
echo $gzbm;
    $query="insert into 员工档案表 (部门体系,工作部门,办事处,岗位名称,职位职级,职位层级,职系,员工编号,员工姓名,性别) values('$bmtx','$gzbm',$bsc,'$gwmc','$zwzj','$zwcj','$zx','$ygbh','$ygxm','$sSex')";
    $result=sqlsrv_query($conn,$query);
if ($result){
echo '插入成功';
}
else{
echo '插入失败';
}

?>

你用中文做表名和字段名?
请把表名和字段名用[]括起,如 [员工档案表] [部门体系] ....

另外,sql server 接受 utf-8 的表名和字段名吗?请核实

你用中文做表名和字段名?
请把表名和字段名用[]括起,如 [员工档案表] [部门体系] ....

另外,sql server 接受 utf-8 的表名和字段名吗?请核实



对,中文做的表名和字段名,不过我之前用query方法对此表做查询都是没有问题的。
用了您的方法还是不管用,另外utf-8的那段代码我去掉了,也没出现什么问题,看来问题也不是这个地方

你用中文做表名和字段名?
请把表名和字段名用[]括起,如 [员工档案表] [部门体系] ....

另外,sql server 接受 utf-8 的表名和字段名吗?请核实



我找到答案了,因为性别那个字段数据库中是规定的2字节,我实际传入的是多个字节,超出了2个字节,所以插入不成功
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

How to make PHP applications fasterHow to make PHP applications fasterMay 12, 2025 am 12:12 AM

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

PHP Performance Optimization Checklist: Improve Speed NowPHP Performance Optimization Checklist: Improve Speed NowMay 12, 2025 am 12:07 AM

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

PHP Dependency Injection: Improve Code TestabilityPHP Dependency Injection: Improve Code TestabilityMay 12, 2025 am 12:03 AM

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.

PHP Performance Optimization: Database Query OptimizationPHP Performance Optimization: Database Query OptimizationMay 12, 2025 am 12:02 AM

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

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function