使用 PHP 查询 SQL Server 数据库 [英] SQL Server Database Query with PHP

查看:68
本文介绍了使用 PHP 查询 SQL Server 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从工作中的 Microsoft SQL Server 数据库获取一些数据.当我有我需要的数据时,我需要制作一个可以在我的电脑本地保存的 Excel 电子表格.

I need to get some data from a Microsoft SQL Server database at work. When I have the data I need, I need to make an Excel spreadsheet that can be saved locally on my computer.

我发现 PHPExcel 似乎可以完成 Excel 部分的工作,但是如何从数据库?

I found PHPExcel which seems to do the job on the Excel part, but what about getting the data from the Database?

我似乎找不到任何最近的东西.只有旧教程.

I can't seem to find anything that's recent. Only old tutorials.

推荐答案

使用这种方式获取记录:

Use this way to Fetch the Records :

<?php
$hostname = "192.168.3.50";
$username = "sa";
$password = "123456";
$dbName = "yourdb";

MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mssql_select_db($dbName) or DIE("Database unavailable");

$query = "SELECT * FROM dbo.table";

$result = mssql_query( $query );

for ($i = 0; $i < mssql_num_rows( $result ); ++$i)
     {
         $line = mssql_fetch_row($result);
         print( "$line[0] - $line[1]\n");
     }
?>

这将从页面上的数据检索和打印中获取每一行.使用您的必需格式.我的意思是,使用 html Table 以良好的格式显示数据.

This will fetch each rows from the Data Retrieve and Print on the Page. Use your Required format into that. I mean, Use html Table to show the data in well format.

这篇关于使用 PHP 查询 SQL Server 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆