PHP无法连接到SQL Server

时间:2015-12-15 14:38:59

标签: php apache sql-server-2005

我正在运行Windows 7(32位)并安装了Apache 2.2和PHP 5.3.1线程安全。我之前尝试过WAMP捆绑包并且不喜欢它,因为我发现它有问题。 apache和PHP组件运行正常。我将apache端口设置为7777,当我转到URL http://localhost:7777/phpinfo.php时,将显示PHP Info。我也可以创建一个基本的PHP Hello World,它可以在浏览器中查看。我需要连接到SQL Server 2005实例以在项目上学习PHP。我已经下载了SQLSRV30.EXE并解压缩了文件并将DLL的php_pdo_sqlsrv_53_ts.dll和php_sqlsrv_53_ts.dll放在文件夹C:\ PHP \ ext中,然后将以下条目放在php.ini文件中

private void acquirePicture(){

ListView lv=(ListView)dialog.findViewById(R.id.listView1);

PackageManager pm=getPackageManager();

List<ResolveInfo> launchables=pm.queryIntentActivityOptions(
this.getComponentName(),new Intent[]{takePicture},
photoPickerIntent,0);

Collections.sort(launchables,
        new ResolveInfo.DisplayNameComparator(pm));

appAdapter=new AppAdapter(pm, launchables);

lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                            long arg3) {
        // TODO Auto-generated method stub
        ResolveInfo launchable=appAdapter.getItem(position);
        ActivityInfo activity=launchable.activityInfo;
        ComponentName name=new ComponentName(activity.applicationInfo.packageName,
                activity.name);

IntentFilter filter = launchable.filter;
            if(filter.actionsIterator() != null){
                Iterator<String > actions = filter.actionsIterator();
            }

            int actioncode;
            Intent  intent = new Intent();
            Uri uri;
            if(filter.hasAction(Intent.ACTION_PICK)){
                actioncode = 1;
                uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                intent.setData(uri);
            }else{
                actioncode = 0;
            }
            intent.setComponent(name);
            startActivityForResult(intent,actioncode);

    }
});

}

class AppAdapter extends ArrayAdapter<ResolveInfo> {
private PackageManager pm=null;

AppAdapter(PackageManager pm, List<ResolveInfo> apps) {
    super(Custom_chooser.this, R.layout.row, apps);
    this.pm=pm;
}

@Override
public View getView(int position, View convertView,
                    ViewGroup parent) {
    if (convertView==null) {
        convertView=newView(parent);
    }

    bindView(position, convertView);

    return(convertView);
}

private View newView(ViewGroup parent) {
    return(getLayoutInflater().inflate(R.layout.row, parent, false));
}

private void bindView(int position, View row) {
    TextView label=(TextView)row.findViewById(R.id.label);

    label.setText(getItem(position).loadLabel(pm));

    ImageView icon=(ImageView)row.findViewById(R.id.icon);

    icon.setImageDrawable(getItem(position).loadIcon(pm));
}
}

重新启动Apache,在phpinfo列表中,它没有说明任何SQL Server属性。当我尝试运行下面的示例时,浏览器会声明 - 致命错误:调用未定义的函数sqlsrv_connect()。我在stackoverflow上找到了几个例子,但它们关注使用wamp。我在这做错了什么?

更新:我实际安装了NetBeans for PHP,并在index.php页面中创建了一个新项目,其代码如下,当我运行它时,错误是相同的

extension=php_pdo_sqlsrv_53_ts.dll
extension=php_sqlsrv_53_ts.dll

1 个答案:

答案 0 :(得分:0)

在另一个论坛上发现了一些内容,暗示微软驱动程序SQLSRV30.exe对我的PHP设置了解得太多了。我正在运行Apache 2.2和PHP 5.3.1,因此发现SQLSVR20.exe驱动程序也兼容PHP 5.3.1所以下载SQLSVR20并用php_pdo_sqlsrv_53_ts_vc6.dll和php_sqlsrv_53_ts_vc6.dll替换文件php_pdo_sqlsrv_53_ts.dll和php_sqlsrv_53_ts.dll(MY PHP设置也在vc6左右)然后修改了php.ini参数。在重新启动Apache时,这进一步完成了这个过程,但是说我需要安装SQL Server 2008 R2 Native Client,然后在PHPInfo网址中列出了SQLSVR并且连接正常工作