Solved

connecting to MS-SQL Server 7.0

Posted on 2000-03-22
15
222 Views
Last Modified: 2008-03-10
Hello, experts!
I have a simple question out here!
I faced a little problem with MSSQL error hiding...
This is my script; it checks if password or login are incorrect by trying to connect to the database, but when it can't connect it not only show's my message: "Cannot grant Access...", but also MSSQL standard message:

Warning: MS SQL message: Login failed for user 'Dmitry'. (severity 14) in C:\InetPub\wwwroot\wlr\login.php3 on line 6
Cannot grant Access to the DataBase!

So, here's the simple script:

<?php
 if ($log!="")
    if (!$conn = mssql_connect("wap", $log, $pwd)) echo "Cannot grant Access to the DataBase!";
 mssql_select_db("NorthWind",$conn) or die ("Can't select database!");    
?>

$log and $pwd are variables that are returned from previous form.

10x in advance,
[Wizz]
0
Comment
Question by:wizzard
  • 7
  • 6
  • 2
15 Comments
 
LVL 8

Expert Comment

by:us111
ID: 2643900
in this function mssql_connect("wap", $log, $pwd)  you connect to the database with login and password to this database. If $log and $pwd are into a table in that database, it won't work.
You have to specify a good login and password to access the database.
Check and grant access in MSSQL.
0
 

Author Comment

by:wizzard
ID: 2643930
Khmmm... I'm not the first day with MSSQL and PHP3, and I asked concrete question ;)

repeating: "I know that I can't connect to the database with wrong l/p!"

This is my script; it checks if password or login are incorrect by trying to connect to the database, but when it can't connect it not only show's my message: "Cannot grant Access...", but also MSSQL standard message:

Warning: MS SQL message: Login failed for user 'Dmitry'. (severity 14) in C:\InetPub\wwwroot\wlr\login.php3 on line 6
Cannot grant Access to the DataBase!

IF I CAN'T CONNECT TO THE DATABASE I WISH TO GET ONLY _MY_ PART OF CODE THAT IS "Cannot grant Access..." BUT NOT THE STANDARD MSSQL ERROR (I WISH TO SHOW MY MESSAGE INSTEAD OF MSSQL ERROR):

Warning: MS SQL message: Login failed for user 'Dmitry'. (severity 14) in C:\InetPub\wwwroot\wlr\login.php3 on line 6.

For now it shows both ;)

BW,
[Wizz]
0
 
LVL 8

Expert Comment

by:us111
ID: 2644000
ah ok ;)
I'm looking for a solution
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:wizzard
ID: 2644006
the line is incorrect in error message, for i've cut some commented lines... ;)
0
 
LVL 8

Expert Comment

by:us111
ID: 2644012
ah ok ;)
I'm looking for a solution
0
 
LVL 8

Expert Comment

by:us111
ID: 2644130
add @ before the function mssql_connect("wap", $log, $pwd))
so it's $conn = @mssql_connect("wap", $log, $pwd))

The @ will ignore the warning
0
 
LVL 8

Expert Comment

by:us111
ID: 2644134
0
 

Author Comment

by:wizzard
ID: 2644149
Eeeh! ;) still it's not the complete solution, for then I don't get my error message too :(

Wizz.
0
 
LVL 2

Accepted Solution

by:
maxkir earned 50 total points
ID: 2644223
Really, I prefer such style:

<?php
    if ($log!="")
    {
        $conn = @mssql_connect("wap", $log, $pwd);
        if(!$conn)
        {
             echo "Cannot grant Access to the DataBase!";
        }
        else
        {
            mssql_select_db("NorthWind",$conn) or die ("Can't select
database!");    
        }  
?>
0
 
LVL 8

Expert Comment

by:us111
ID: 2644250
Are you sure. I've tested with mysql, same as mssql

<?
if (!$conn = @mysql_connect("localhost", "klkilk", "uweiruo"))
        echo "Cannot grant Access to the DataBase!";
@mysql_select_db("NorthWind",$conn) or die ("Can't select database!");
?>

returns me:
Cannot grant Access to the DataBase!Can't select database!
0
 

Author Comment

by:wizzard
ID: 2644269
BTW, It DIDN'T work ;) (reg. your last comment)
So, I've changed some things and got a working version! :P

Well, Excellent Job!
Here's your "A" grade, thanks again!

BW,
Wizz.
0
 

Author Comment

by:wizzard
ID: 2644290
Oooh, us111.... it wasn't your answer... :(
Well, I'll have new questions soon!
Sorry.

Wizz.
0
 
LVL 2

Expert Comment

by:maxkir
ID: 2644355
I'm sorry, if answer mine or not ? If it is us111's, I'm ready to post a question for him.
0
 

Author Comment

by:wizzard
ID: 2644394
;) well, maxkir, your answer was checked and worked - that's it!
10x,
Wizz.
0
 
LVL 8

Expert Comment

by:us111
ID: 2644498
hey very bad boy :))
never mind :))
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question