Hi
I want to connect PHP to SQL Server. I use the following code [php]<?
$connection = mssql_connect($host,$username,$password) or die("Couldn't connect to SQL Server on");
?>[/php]but nothing is displayed. I don't know what are the requirements for connecting to sql server
looking for ur help.
Thank's
12 1605
Greetings and welcome.
Nothing is displayed because you have not asked it to display anything. If all the information you have provided it is correct ($host, $username, $password) it should connect. How to test if it has is adding one line of code: (I havce changed this to mysql instead of your mssql, so provided the syntax is the same, just change that (I have never used mssql)
[PHP]<?php
$connection = mysql_connect($host,$username,$password) or die('I cannot connect to MySQL because: ' . mysql_error());
echo('I have successfully connected');
?>[/PHP]
What I have done:
1. Don't be lazy - Write out <?php instead of just <? for good practice and in future versions of php that will not work I believe.
2. In the die() function I have written your message (I cannot connect to MySQL because:) in a string and then combined it with the mysql_error() function which displays the error that it has run into. Mssql might have a different function, I am not sure.
3. Made an echo statement which will mean something is displayed on the screen if it ran successfully. The die() function will stop the code there if there is a problem and not display the echo line, but only the die() error.
Hope that helps, but I recommend looking at some tutes if you are still confused.
Hi
I want to connect PHP to SQL Server. I use the following code
<?
$connection = mssql_connect($host,$username,$password) or die("Couldn't connect to SQL Server on");
?>
but nothing is displayed. I don't know what are the requirements for connecting to sql server
looking for ur help.
Thank's
The very fact that nothing is written to the browser shows you have successfully connected to your database.
Congratulations :)
Thanks for replying. Sorry for writing incomplete code. I use[php]<?
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$host="LOCALHOST";
$database="testgenerator";
//$connection = mysql_connect($host,$username,$password);
$connection = mssql_connect('HAMAYUN\\SQLServer','sa','hama') or die("SQL Server Error");
echo "hello";
?>[/php]
This display nothing the time when i post on the form.
By searching the google I find that I have to uncomment the line
extension=php_mssql.dll in php.ini.
Now die("SQL Server Error"); is executed and i see the following output on page
SQL Server Error. It means I cannot connect to sql server.
Also I used the following[php]<?
$connection = mssql_connect('HAMAYUN\SQLServer','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('Localhost\SQLServer','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('Localhost','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('.\SQLServer','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('My IP','sa','hama') or die("SQL Server Error");
?>[/php]
as mension in some helps but no succes.
Sql server management studio use the following to connect to sql server
"Hamayun\SQLServer","sa","hama"
Now how to connect to sql server 2005.
Looking for quick Help
Thanks
Thanks for replying.
Sorry for writing incomplete code. I use
<?
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$host="LOCALHOST";
$database="testgenerator";
//$connection = mysql_connect($host,$username,$password);
$connection = mssql_connect('HAMAYUN\\SQLServer','sa','hama') or die("SQL Server Error");
echo "hello";
?>
This display nothing the time when i post on the form.
By searching the google I find that I have to uncomment the line
extension=php_mssql.dll in php.ini.
Now die("SQL Server Error"); is executed and i see the following output on page
SQL Server Error. It means I cannot connect to sql server.
Also I used the following
<?
$connection = mssql_connect('HAMAYUN\SQLServer','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('Localhost\SQLServer','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('Localhost','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('.\SQLServer','sa','hama') or die("SQL Server Error");
$connection = mssql_connect('My IP','sa','hama') or die("SQL Server Error");
?>
as mension in some helps but no succes.
Sql server management studio use the following to connect to sql server
"Hamayun\SQLServer","sa","hama"
Now how to connect to sql server 2005.
Looking for quick Help
Thanks
You're not using any statements to check the connection:
[php]
$connection = mssql_connect(CONNECTION_DETAILS) or die(mssql_error);
if($connection)
{
echo "Connected";
}
else
{
echo "Problem with connection";
}
[/php]
Notice the mssql_error - using this will give you exact error info.
warning:
Please enclose your posted code in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use [code] tags in future.
MODERATOR
I get the out put "SQL Server Error" which is the die() statement of the line 6 of code[php]<?
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$host="LOCALHOST";
$database="testgenerator";
//$connection = mysql_connect($host,$username,$password);
$connection = mssql_connect('HAMAYUN\\SQLServer','sa','hama') or die("SQL Server Error");
echo "hello";
?>[/php]this means that there is some problem while connecting the server.
I get the out put "SQL Server Error" which is the die() statement of the line 6 of code
<?
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$host="LOCALHOST";
$database="testgenerator";
//$connection = mysql_connect($host,$username,$password);
$connection = mssql_connect('HAMAYUN\\SQLServer','sa','hama') or die("SQL Server Error");
echo "hello";
?>
this means that there is some problem while connecting the server.
Right.
Take a look at my last post and change the part that says
[php]
mssql_error()
[/php]
Change it to
[php]
mssql_get_last_message()
[/php]
Regards.
I use this [php]<?
mssql_connect("Hamayun\SQLServer","xxx","xxx") or die("SQL Error:" . mssql_get_last_message());
?>[/php]
the only output i get
SQL Error:
Hamayun Khan this is the last warning. You must use code tags when you display any code! Failing to comply with the Posting guidelines will result in a ban from this site.
moderator
Hamayun Khan this is the last warning. You must use code tags when you display any code! Failing to comply with the Posting guidelines will result in a ban from this site.
moderator
Sorry for not using the right code tags.
I m using <? ?> for php <% %> for asp. I don't know what r the right code tags.
Would you please give me one example so that i will use in future.
Thanks
Hamayun Khan this is the last warning. You must use code tags when you display any code! Failing to comply with the Posting guidelines will result in a ban from this site.
moderator
Is this is right.
[php]<?
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
$host="LOCALHOST";
$database="testgenerator";
//$connection = mysql_connect($host,$username,$password);
$connection = mssql_connect( 'HAMAYUN\\SQLServer','sa','hama') or die("SQL Server Error");
echo "hello";
?>[/php]
Hamayun Khan this is the last warning. You must use code tags when you display any code! Failing to comply with the Posting guidelines will result in a ban from this site.
moderator
[php]
<?
mssql_connect("Hamayun\\SQLServer","xxx","xxx") or die("Error")
?>[/php]
OK I find the way
Thank's
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Google Mike |
last post by:
After a lot of thought and research, and playing with FreeTDS and
InlineTDS, as well as various ODBC connections, I have determined that
the fastest and cheapest way to get up and going with PHP on...
|
by: Ann Marinas |
last post by:
Hi all,
I would like to ask for some help regarding separating the asp.net
webserver and the sql server.
I have created an asp.net application for a certain company. Initially,
we installed...
|
by: Ann Marinas |
last post by:
Hi there,
I am currently developing an ASP.NET program that connects to a SQL Server
2000 database. I also have SQL Server 2005 Express installed on the same
local machine.
Prior to...
|
by: cj.snead |
last post by:
Hello,
I am having trouble connecting to a remote named instance of SQL Server
via Pocket PC. I have had absolutely no luck connecting with VS 2005
(even to a default instance), so I wen't back...
|
by: Vinod R.Shenoy |
last post by:
Hi All,
Came across a post wherin you had helped somebody with a similar
problem and was wondering if you could help us out with it.
Our problem is ,
We have a development SQL Server 2000...
|
by: Todd Brewer |
last post by:
Windows Server 2000
ASP.NET 2.0
SQL Server 2000 (on a physically seperate server)
I moved an ASP.NET 2.0 application from a development server to production,
and am getting the following error:...
|
by: mairhtin o'feannag |
last post by:
Hello,
I'm having problems connecting to my new v9 db box. The pertinent
information is below:
DB2_db2inst1 60000/tcp
DB2_db2inst1_1 60001/tcp
DB2_db2inst1_2 60002/tcp
DB2_db2inst1_END...
|
by: samadams_2006 |
last post by:
Hello,
I have a problem that I'm hoping someone will be able to help me
resolve.
1) I have a C# Web Site in which I connect to the database: "Install
Microsoft SQL Server 2005 Express...
|
by: orandov |
last post by:
Hi,
I am having a problem connecting my .net applications from the
application server to the database server. When I run the application
from my windows xp (sp2) box it works fine. When I try to...
|
by: aboutjav.com |
last post by:
Hi,
I need some help. I am getting this error after I complete the asp.net
register control and click on the continue button. It crashed when it
tries to get
it calls this Profile property
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |