无法从php脚本连接到sql [英] Can't connect to sql from php script

查看:45
本文介绍了无法从php脚本连接到sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,所以我一直在阅读所有相关主题,但它们仍然没有帮助我解决我的问题.我是 php 的新手,所以非常感谢任何帮助.我试图通过在 php 中使用 select 语句来创建一组客户,但无法连接到数据库.

Hey guys, So I've been reading all the related topics but they still haven't helped my solve my problem. I am new to php, so any help is greatly appreciated. I am trying to make an array of customers by using a select statement in php but can't connect to the database.

我收到此错误:在第 20 行的 script 中调用未定义的函数 mssql_connect().有什么想法吗?再次感谢!

I get this error: Call to undefined function mssql_connect() in script on line 20. Any thoughts? Thanks again!

和代码:$serverName = "*";
$uid = "*";
$pwd = "*";
$databaseName = "
**";

And the code: $serverName = "*";
$uid = "*";
$pwd = "*";
$databaseName = "
**";

$connectionInfo = array( "User"=>$uid,                              
                        "Password"=>$pwd,                              
                        "Database"=>$databaseName);   

/* Connect using SQL Server Authentication. */    
$conn = mssql_connect($serverName, $connectionInfo);    

$tsql = "SELECT FirstName, LastName, EmailAddr FROM Customer";   

/* Execute the query. */    
$stmt = mssql_query($conn, $tsql);    

if ($stmt)    
{    
    while($row = mysql_fetch_array( $stmt, MSSQL_FETCH_ASSOC))
    {
        $FirstName = $row["FirstName"];
        $LastName = $row["LastName"];
        $EmailAddr = $row["EmailAddr"];
        echo "$FirstName";
        echo "$LastName";
        echo "$EmailAddr";
    }
}     
else     
{    
    echo "Submission unsuccessful.";
    die(print_r( mssql_errors(), true));    
}

/* Free statement and connection resources. */    
mssql_free_stmt($stmt);    
mssql_close($conn);

推荐答案

产生这个错误是因为你没有从 php.ini 文件打开 MicroSoft SQL server ddl 文件.

This error is generating because you have not open MicroSoft SQL server ddl file from php.ini file.

要使其可用,请按照以下步骤操作

To make this available follow this steps

1) 打开你的 php.ini 文件2) 搜索 ;extension=php_mssql.dll3)通过删除;"取消注释第一的4) 重启你的服务器

1) Open your php.ini file 2) search for ;extension=php_mssql.dll 3) uncomment it by removing ";" first 4) Restart your server

问候

这篇关于无法从php脚本连接到sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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