Jump to content

Help with connecting to SQL


ThreeTrees

Recommended Posts

Hi

I recently had to change my database from mysql to sql. with mysql I didnt have any problem but now I cant connect to the sql database.

 

here's the sql connection code

 

<?php
$myServer = "localhost";
$myUser = "sa";
$myPass = "mypassword";
$myDB = "mmt";

$dbhandle = mssql_connect($myServer, $myUser)
  or die("Couldn't connect to SQL Server on $myServer");

$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");

mssql_close($dbhandle);
?>

 

 

and thats the mysql connection if that helps

 

?php

$con= mysql_connect('localhost','root') or die ('cannot connect bla bla' . mysql_error());
if (!$con) { echo 'WHAT THE FUCK CONNECTION ISNT WORKING'; }

mysql_select_db('mmt') or die ('db fail' . mysql_error());
if (!mysql_select_db('mmt')) { echo ' OH NOES UNDER DAS VEINDER DATABASE'; }

?>

Link to comment
https://forums.phpfreaks.com/topic/118239-help-with-connecting-to-sql/
Share on other sites

How long ago did you switch to SQL? If it was a short time, it's possible that thnigs haven't... connected... yet.

 

I have it for a few days

and Im able to connect it using the sql manager

 

could it be that  my connection script is wrong?

if any of you guys know any better script it would probably help

please use this

 

<?php
$myServer = "localhost";
$myUser = "sa";
$myPass = "mypassword";
$myDB = "mmt";

$dbhandle = mssql_connect($myServer, $myUser, $myPass )
  or die("Couldn't connect to SQL Server on $myServer");

$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");

mssql_close($dbhandle);
?>

 

you have not mentioned the password while connecting to sql server

please use this

 

<?php
$myServer = "localhost";
$myUser = "sa";
$myPass = "mypassword";
$myDB = "mmt";

$dbhandle = mssql_connect($myServer, $myUser, $myPass )
  or die("Couldn't connect to SQL Server on $myServer");

$selected = mssql_select_db($myDB, $dbhandle)
  or die("Couldn't open database $myDB");

mssql_close($dbhandle);
?>

 

you have not mentioned the password while connecting to sql server

 

gives me the same error

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.