I am using a script php that connect to sqlserver but it doesn't works.
//connection to the database
$dbconn = mssql_connect($Server)
or die("Couldn't connect to SQL Server on $Server");
if($dbconn)echo 'Connected';
//select a database to work with
$selected = mssql_select_db($DB, $dbconn)
or die("Couldn't open database $myDB");
![when running script it gives this error, i m using windows authentication][1]
http://i.stack.imgur.com/a9ndN.jpg
Check mysql_connect()
$dbconn = mysql_connect('hostname','username','password');
Connect using mysql_connect()
$dbconn =mysql_connect(servername,username,password);
example
$con = mysql_connect("localhost","me","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
Related
I am trying to write php to connect data from myqsl (i use free host 000webhost.com)
file connect:
<?php
$connect = mysqli_connect("files.000webhost.com:21", "nguyendang", "password", "foodcourt_db") or die ("could not connect to sever " . mysqli_connect_error()) ;
mysqli_query($connect, "SET NAMES 'utf8'");
?>
I had these errors when i ran
Try hostname with localhost. And also check the MySQL server is currently running.
This may happen in hosting for less duration due to overload of MySQL Server
Try to use this connection:
$link = mysqli_connect("localhost", "username", "password", "database_name");
//check connection
if($link === false) {
die("ERROR could not connect. " .mysqli_connect_error());
}
I am trying to access localhost db from remote server .
$link = mysql_connect('192.168.65.44', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
Warning: mysql_connect(): Can't connect to MySQL server on '192.168.65.44' (4) in /home/xx/xx/xx/xx/xx
Could not connect: Can't connect to MySQL server on '192.168.65.44' (4)
The error tells that there's a problem in your host. If you are trying locally in your system, use
$link = mysqli_connect('localhost', 'root', '');
Note : mysql_ is deprecated. You need to use either Improved Mysqli (mysqli_) or PDO.
put "localhost" in place of "192.168.65.44" in
mysql_connect
Try this it will work :
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
i've tried everything to make my site connect to the database but i always get his error: Could not connect to Master Database
i have 2 files
define('DBHOST','localhost');
define('DBUSER','root');
define('DBPASS','root');
define('DBNAME','test');
define('dbslave','test');
define('dbsiteid','1');
define('dbprefix','_blog');
and connect.php
error_reporting(0);
$connect = mysql_connect("$DBHOST", "$DBUSER", "$DBPASS");
if ( ! $connect) {
die('Could not connect to Database server');
}
$siteid = "$dbsiteid";
$prefix = "$dbprefix";
$dbmast = "$DBNAME";
$dbslave = "$dbslave";
$cmast = mysql_select_db("$DBNAME");
if ( ! $cmast) {
die('Could not connect to Master Database');
}
$cslave = mysql_select_db("$dbslave");
if ( ! $cslave) {
die('Could not connect to Slave Database');
}
how do i solve this error with connection or what i did wrong ?
You do not put constants in quotes, they do not start with $, and by convention are all uppercase.
define('DBHOST','localhost');
define('DBUSER','root');
define('DBPASS','root');
define('DBNAME','test');
define('DBSLAVE','test');
define('DBSITEID','1');
define('DBPREFIX','_blog');
$connect = mysql_connect(DBHOST, DBUSER, DBPASS);
if (!$connect) {die('Could not connect to Database server');}
$cmast = mysql_select_db(DBNAME);
if (!$cmast) {die('Could not connect to Master Database');}
$cslave = mysql_select_db(DBSLAVE);
if (!$cslave) {die('Could not connect to Slave Database');}
Also, defining constants only to assign them to variables is silly and a waste of resources. And don't turn off error reporting when developing as it hides your errors. You want to do the opposite and them them on.
I'm connecting to Mysql Database With following code. I'm using mysqli. But It's not connecting to mysql database.
define("HOST", "hostname");
define("USER", "username");
define("PASS", "password");
define("DB", "dbname");
$link = mysqli_connect(HOST, USER, PASS) or die("Couldn't make database connection.");
$db = mysqli_select_db($link, DB) or die("Couldn't select database");
Strange things is that when I delete or die("Couldn't make database connection.") and or die("Couldn't select database"); then it's connect to db. Why ? Is there anything I'm doing wrong ?
This is the proposed way to handle the situation:
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
Ok, Ive been playing around with PHP and databases. Note, Im doing all my work on a webserver hosted by bluehost.
So I went into the cpanel and set up a database called gagalugc_stocks.
I also setup a username (test) and a password (password) and added them to be able to control the databse. Below is my script in an attempt to connect to it, not it is also on the server.
<?php
$connect = mysql_connect('localhost','test','password');
if(!$connect){die('Could not reach database!');}
mysql_select_db("gagalugc_stocks", $connect)
?>
-Thanks
NOTE: The problem is that it can never reach the database.
<?php
$connection = mysql_connect ('localhost', 'test', 'password')
or die ('<b>Could not connect: </b>' . mysql_error());
$result = mysql_select_db("gagalugc_stocks")
or die ('<b>Could not connect: </b>' . mysql_error());
?>
Didn't check for port when adding database make sure to specify host and port
(localhost:2083)
How about
<?php
$connect = mysql_connect('localhost:2083','test','password');
if(!$connect){die('Could not reach database!');}
mysql_select_db("gagalugc_stocks", $connect)
?>
For local system:-
$con = mysql_connect("localhost","root","");
if (!$con){
die('Unable to connect to the server ' . mysql_error());
}
mysql_select_db("databasename", $con) or die(mysql_error());
For website or remote server:-
$con = mysql_connect("localhost","username","password");
if (!$con){
die('Unable to connect to the server ' . mysql_error());
}
mysql_select_db("databasename", $con) or die(mysql_error());
for more please visit : Algosoftwares