Solved

connecting to MS-SQL Server 7.0

Posted on 2000-03-22
15
220 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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now