Solved

connecting to MS-SQL Server 7.0

Posted on 2000-03-22
15
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
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…

627 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