视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
php如何连接MSSQLServer数据库
2020-11-09 10:03:39 责编:小采
文档

如何连接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阅读我们的

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

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

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

    //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<= $colName; $j++)
    {
    echo "

    ";
    }

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

    ";
    for($i=1;$i<=odbc_num_fields($result);$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 < count($objects); $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);
    }

    下载本文
    显示全文
    专题