php 如何连接MS SQL Server 数据库

php中文网
发布: 2016-06-07 17:47:03
原创
1424人浏览过

如何连接ms sql server

下面是连接到MSSQL服务器数据库代码。

$myServer = "localhost";
$myUser = "your_name";
$myPass = "your_password";
$myDB = "examples";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
  or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");

//declare the SQL statement that will query the database
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'";

//execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result);
echo "

" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned

";

//display the results
while($row = mssql_fetch_array($result))
{
  echo "

  • " . $row["id"] . $row["name"] . $row["year"] . "
  • ";
    }
    //close the connection
    mssql_close($dbhandle);
    ?>

    DSN的主张'数据源名称'。这是一个简单的方法来分配,容易rememberable有用的数据

    源的名称可能不局限于单独的数据库。如果您不知道如何建立一个系统DSN阅读我们的

    立即学习PHP免费学习笔记(深入)”;

    教程如何建立一个系统DSN。

    在下面的例子,我们将告诉你如何以一MSSQL服务器数据库DSN所谓'连接

    examples.mdb'和检索所有的记录表中的'车'。

    中国工商网电子商务购物中心系统EMall
    中国工商网电子商务购物中心系统EMall

    完全公开源代码,并无任何许可限制 特别基于大型电子商务网站的系统开发 Microsoft SQL Server 2000后台数据库,充分应用了存储过程的巨大功效 基于类模块的扩展数据访问能力支持任何类型的大型数据库 加密用户登录信息(cookie) 易于安装的系统和应用功能 100%的asp.net的代码,没有COM,java或者其他的格式 完全基于MS建议的系统安全设计 最佳的应用程序,数据库

    中国工商网电子商务购物中心系统EMall 0
    查看详情 中国工商网电子商务购物中心系统EMall

    //connect to a DSN "myDSN"
    $conn = odbc_connect('myDSN','','');

    if ($conn)
    {
      //the SQL statement that will query the database
      $query = "select * from cars";
      //perform the query
      $result=odbc_exec($conn, $query);

      echo "

    ";

      //print field name
      $colName = odbc_num_fields($result);
      for ($j=1; $j   { 
        echo "

    ";
      }

      //fetch tha data from the database
      while(odbc_fetch_row($result))
      {
        echo "

    ";
        for($i=1;$i     {
          echo "";
        }
        echo "";
      }

      echo " ";
      echo "

    ";
        echo odbc_field_name ($result, $j );
        echo "
    ";
          echo odbc_result($result,$i);
          echo "
    ";

      //close the connection
      odbc_close ($conn);
    }
    else echo "odbc not connected";
    ?>
    =======================

    php  如何把pdf文件转换成txt文本文件

    文档格式(PDF)是一种文件格式创建的文件交换。每个PDF文件封装了一个固定布局

    的2D文件的完整说明(和,与Acrobat 3D软件,嵌入式3D文件),其中包括文字,字

    体,图像和二维矢量图形,撰写文件。

    function pdf2text($filename) {

        // Read the data from pdf file
        $infile = @file_get_contents($filename, FILE_BINARY);
        if (empty($infile))
            return "";

        // Get all text data.
        $transformations = array();
        $texts = array();

        // Get the list of all objects.
        preg_match_all("#obj(.*)endobj#ismU", $infile, $objects);
        $objects = @$objects[1];

        // Select objects with streams.
        for ($i = 0; $i         $currentObject = $objects[$i];

            // Check if an object includes data stream.
            if (preg_match("#stream(.*)endstream#ismU", $currentObject,

    $stream)) {
                $stream = ltrim($stream[1]);

                // Check object parameters and look for text data.
                $options = getObjectOptions($currentObject);
                if (!(empty($options["Length1"]) && empty($options["Type"]) &&

    empty($options["Subtype"])))
                    continue;

                // So, we have text data. Decode it.
                $data = getDecodedStream($stream, $options); 
                if (strlen($data)) {
                    if (preg_match_all("#BT(.*)ET#ismU", $data,

    $textContainers)) {
                        $textContainers = @$textContainers[1];
                        getDirtyTexts($texts, $textContainers);
                    } else
                        getCharTransformations($transformations, $data);
                }
            }

        }

        // Analyze text blocks taking into account character transformations

    and return results.
        return getTextUsingTransformations($texts, $transformations);
    }

    PHP速学教程(入门到精通)
    PHP速学教程(入门到精通)

    PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

    下载
    来源:php中文网
    本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
    最新问题
    开源免费商场系统广告
    热门教程
    更多>
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
    php中文网:公益在线php培训,帮助PHP学习者快速成长!
    关注服务号 技术交流群
    PHP中文网订阅号
    每天精选资源文章推送

    Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号