您当前的位置: 首页 >  sql

dawn

暂无认证

  • 7浏览

    0关注

    204博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

PHP(2):PHP读取MS Sql Server 2014数据库数据

dawn 发布时间:2021-11-09 19:46:00 ,浏览量:7

  前面使用VBS将Excel数据写入到了Ms Sql Server 2014的数据库,现在要将记录显示出来,本来打算用IIS+ASP.net,可是9月份安装好Apache+PHP后一直没有写过PHP代码,还是要学一学PHP ,很多人说PHP是最好的编程语言,还是要体会一下。

  本来想着很简单的事情,没有想到又是不停地踩坑!

  先是在网上搜索了PHP读Ms Sql Server数据库的代码,照着样子写,结果总是报错,查原因,原来是PHP对读写Ms Sql Server数据库的支持文件有要求,我使用的是PHP 7.4,按照网上说的反复试,折腾了4个小时,最终报告了下面的错误:

   心气烦躁是折腾不好的,上面已经看到了曙光,必须冷静下来,查了资料,支持库有线程安全和不安全之分,还有PDO和非PDO之分,应该分别试,先用phpinfo()查看7.4的库情况,就使用PDO,加上下面的指令到php.ini中:

  extension=G:\php74\ext\php_pdo_sqlsrv_74_ts_x64.dll

  重启Apache,好了,读出数据来了!

  ● 按照上面的方法在Win7-64位系统上正常了,后面我在Win10-64位的企业版上安装Apache,数据库仍然用MS SQL Server 2014,结果却一直报告错误,折腾了好长时间才明白,需要安装ODBC,我在微软的官网上下载后安装,数据就读出来了,正常了!链接地址:Download Microsoft® ODBC Driver 11 for SQL Server® - Windows from Official Microsoft Download Center】

  ● 这个链接地址有详细资料:System requirements - PHP drivers for SQL Server | Microsoft Docs

  开始做前端显示页面,一个月前看过easyUI的资料,比较简单,看资料写代码:




    
    
    
    网络设备信息
    
    
    
    
    


    
添加
IP地址> MAC地址> 网关地址> 子网掩码> 主DNS> 备DNS> 操作系统> 内存大小> 硬盘大小> 硬盘系列号> CPU> 使用人> 联系电话> 设备名称> 地点> 录入时间> 操作> $("#dataGridNetInfo").datagrid({ title:"网络设备表", iconCls:"icon-save", height:800, url:'GetInfoFromMsSqlServer.php',//加载数据URL toolbar:"#dataGridToolBar", rownumbers:true,//加入行号 checkOnSelect:true, fitColumns:false,//列宽自适应 striped:true,//斑马线 //datagrid数据加载完毕之后执行的代码 onLoadSuccess:function () { $(".opAdd").linkbutton({ iconCls:"icon-cancel", }); $(".opUpdate").linkbutton({ iconCls:"icon-edit", }); }, pagination:true, }); $("#dataGridToolBar>a:contains(删除)").linkbutton({ iconCls:"icon-remove", }); $("#dataGridToolBar>a:contains(添加)").linkbutton({ iconCls:"icon-add", }); $("#searchIp").textbox({ width:220, buttonIcon:"icon-search", buttonText:"搜索", }); //格式化字符串函数 function operatingSystem(value,row,index) { var sReturn="other"; if(value.indexOf('Windows 7')!=-1){ if(value.indexOf('32-bit')>0){ sReturn='Windows 7 32位'; }; if(value.indexOf('64-bit')>0){ sReturn='Windows 7 64位'; }; }; if(value.indexOf('Windows 10')!=-1){ if(value.indexOf('32-bit')>0){ sReturn='Windows 10 32位'; }; if(value.indexOf('64-bit')>0){ sReturn='Windows 10 64位'; }; }; if(value.indexOf('Windows XP')!=-1){ sReturn='Windows XP'; }; return sReturn; }; function operateButton(value,row,index) { return ' 删除 修改' }

  然后就是用php的编写后台代码文件,继续踩坑:


  显示结果:

   折腾了一整天,终于搞定了。

关注
打赏
1664252102
查看更多评论
立即登录/注册

微信扫码登录

0.2181s