Connecting to an MSSQL database through ODBC Error - php

Where to start..
I have a server with windows 2008 R2 standard 32 bits.
On that server ISS 7 is installed and a php site is added but requires databases.
Made an sql database on that server wich is called 'test'.
ODBC connection is made and tested and it succeeded.
Now when I use this php code to connect to the server it gives me:
Can not connect because the target machine actively refused it.
php code:
<?
### Database ###
$user = "*****"; //database user
$pass = "*****"; //database password
$host = "localhost"; //database location
$db = "test"; //database name
##mysql_connect ("$host","$user","$pass");
##mysql_select_db("$db");
$dbConn = odbc_connect("$db","$user","$pass","$host") or die(odbc_errormsg());
?>
The password and username are correct but the error still remains.
Any help is appreciated!

Have you set your datasource using administrative tools, data sources, System DSN?
if not i'm sure it won't find the database.
see this link: http://support.microsoft.com/kb/305599

Related

Connection refused "mysqli_connect(): (HY000/2002): Connection refused in **************************conn.php on line 6 Failed

Hey guys I have problem with connecting my .php file to database, I've tried different ways but still the same response.
Here is my code (updated):
<?php
$server_name = "localhost";
$mysql_username = "*****";
$mysql_password = "*****";
$db_name = "*****";
$conn = mysqli_connect ($server_name, $mysql_username, $mysql_password, $db_name);
if($conn) {
echo "Success";
}
else {
echo "Failed";
}
?>
UPDATE
Guys, when I connect to localhost everything works fine but I would like to connect to a server and be able to upload data from different android devices. Currently I use 000webhost.com free service, so might it be the key point and problem that I didn't upgrade that to PRO?
mysqli_connect requires the arguments to be in the order servername, username, password, databasename. Your order is servername, databasename, username, password.
The code should be:
$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, $db_name);
You sequence of parameter is wrong
<?php
$server_name = "*****";
$db_name = "*****";
$mysql_username = "*****";
$mysql_password = "*****";
$conn = mysqli_connect($server_name, $mysql_username,$mysql_password, $db_name);
if($conn) {
echo "Success";
} else {
echo "Failed";
} ?>
Correct syntax
mysqli_connect(host,username,password,dbname,port,socket);
Reference mysqi_connect
EDIT
A extra tip
$conn = mysqli_connect("localhost","username","password","db_name");
Put values according to you server.
EDIT 2
MySQL needs to be running on the port 3306 make sure it is correct
From the comments and from the ruling out of other possibilities indicated in the other answers, it is quite possible it is a connection issue with your service provider.
You should write to them explaining your situation, if at all they have support for free services. You should probably change the passwords to some dummy ones in case you have share it with them; Some service providers ask you to share your password for them to check, not sure if it's recommended practice.
Also, for testing and development, it's better you use some kind of local installation of PHP, such as XAMPP or WAMPP etc, so that you can have control during development and testing. If something works on your local installation and not on the remote, having a development installation is useful to isolate and report such issues.
I think your problem is that you did not instantiate the class, remedied by making it $conn = new mysqli ($server_name, ..... . Also, your sequence of parameters is incorrect. It should be server, user, password and finally database.
In addition, you should be using PHP constants instead of variables for this, so $server_name should be SERVER_NAME. Similarly $mysqli_username, $mysqli_password, and $db_name should be changed. Not that I wouldn't work as you have it, but it just is not proper.
Iy you are using MAMP, the default port for mysql is 8889, but the "traditional" port that php expects to use for mysql is 3306.
So you need to open MAMP and change the MAMP mysql port to 3306, then restart the mysql server. Now the connection should be successful.

SMS GATEWAY USING OZEKING MYSQL + PHP

I'm trying to configure an SMS GATEWAY USING OZEKING but I'm getting an error which has something to do with MYSQL ODBC DRIVER not being found. I have the driver installed on my Windows 10 machine and I'm not sure if I'm doing the right thing. In the OZEKING configuration I'm seeing this in the picture below:
The error I'm getting is :
12/16/2015 14:51:47 - INFO 6021: Connecting to database ODBC, DRIVER={MySQL ODBC 5.3 Driver};Server=localhost;Database=dbtest;UID=root;PWD=password#87;.
12/16/2015 14:51:47 - ERROR 6001: Database connection error: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified. ODBC;DRIVER={MySQL ODBC 5.3 Driver};Server=localhost;Database=dbtest;UID=root;PWD=password#87;
12/16/2015 14:51:47 - INFO 6026: Will try to reconnect to database in 20 seconds.
My question is what exactly am I doing wrong?
These parameters I'm entering Server=localhost;Database=dbtest;UID=root;PWD=password#87 are the ones I'm using to connect to my database, i.e:
$serverName = "localhost";
$userName = "root";
$password = "password#87";
$databaseName = "dbtest";
//create connection and select database by given data
$GLOBALS["connection"] = mysql_connect($serverName, $userName, $password);
if ($GLOBALS["connection"] == null)
{
echo mysql_error() . "<br>";
return false;
}
Anyone to assist me the correct way of doing things. Thanks.
ODBC drivers installed are 32-bit OR 64-bit, make sure you installed the correct architecture for your machine.
(install both to be safe)
Click Start and type "ODBC", you'll be given an option for your 32-bit and 64-bit sources, check them both and make sure your 5.3 driver is installed under both.

ODBC Connection with integrated security PHP and MS SQL Server

I need the guidance help on ODBC connection string in PHP, which I am using to connect to MS SQL Server.
<?php
$server = 'UKEMO03';
$database = 'mtpFetch';//the database to connect to
$user = 'shoabg';// the user has PERMISSIONS AT THE DATABASE
$pass = 'Shsx12x';//and here the user's password
$dsn = "Driver={SQL Server};Server=$server;Database=$database;";
$connect = odbc_connect($dsn, $user, $pass);
?>
Above code works treat, but i have a requirement of not to specify the username and password and use the connection string with Integrated Security. I can't find anything on internet and I can't change the connection string method because I've completed most of my work and by adapting another connection method will require a massive change in a code in theory its not an option for me.
Is there a way we can create Integrated Security connection to connect MS SQL Server in PHP using ODBC
Please help i don't know what to do
This will connect you to the ODBC master database (cathalog).
I did not succeed to connect to another database. There is an option for default database in the configuration of ODBC SDN, but has no effect
("Chenge the default database to").
$this->dbHandle = odbc_connect("Driver={SQL Server};Server=localhost;Integrated Security=SSPI", '', '');
If you use PHP ini make sure you use:
mssql.secure_connection=On
On the database server, make sure you have Windows Authentification associated with your login username

Having trouble with connecting to MySQL database in php

I've made mysql.php file which contain codes to connect to my database.
However, i'm getting this error message over and over again.
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 7
Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to MySQL server on 'localhost' (10061) in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 8
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 8
Unable to select database
I've checked if my username, host, database, and password were misspelled, but they were all correct.
I've looked around the internet, but couldn't seem to find the right one for my problem.
My mysql.php file contains:
<?php
// Mysql settings
$user = "example_example";
$password = "example";
$database = "example_example";
$host = "localhost";
mysql_connect($host,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
?>
I've changed my user, password and host name to "example".
I just couldn't find the solution for myself, and I need your kind help.
Thank you in advance.
Please try to find out the error by using mysql_error() function as follows :
mysql_connect($host,$user,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
and then try to find the exact reason for the failure.
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061)
here a list of questions you have to do when this error appears:
1.- is mysql running on the server?
1.1.- is mysql running on default port or in a custom port?
1.2 - is mysql accepting connexions (from localhost, from an ip...?
1.3 - your firewall is blocking mysql?
2.- the database exists on the server?
3.- the user:password have access to that database?
3.1- the user:password can log in from localhost, from an ip... from any place that mysql
is accepting?
I think I don't forget anything
Please check first that your mysql server is running properly.
Mysql settings
$user = "example_example";
$password = "example";
$database = "example_example";
$host = "localhost";
$cn=mysql_connect($host,$user,$password);
mysql_select_db($database,$cn);
Please try this it may work
I am not expert of php but this code is working perfectly in my website
if you are getting any error after applying this code then please inform me i will rty to solve the problem.
Thanks
You should provide the connection that need to use from database whle selecting database. Also use single quote instead of double quotes.
<?php
// Mysql settings
$user = 'example_example';
$password = 'example';
$database = 'example_example';
$host = 'localhost';
$link = mysql_connect($host,$user,$password);
mysql_select_db($database,$link) or die( "Unable to select database");
?>
Reference
You have to get the database information first. You posted this problem when you try to connect to your database in your website hosting, right?
So, go to your hosting control panel to get the MySQL database (and take note of where the database is stored on! Sometimes some hosting providers don't use "localhost". Instead, some of them may use 'serverXX.yourhostingprovider.tld' where XX means the server ID), and then change the corresponding variables with the value you've obtained from the hosting control panel.

how to remote database mysql XAMPP from another computer?

the script of connection =
<?
$server = "192.168.0.167";
$username = "root";
$password = "";
$database = "dbbook";
mysql_connect($server,$username,$password) or die("Koneksi gagal");
mysql_select_db($database) or die("Database tidak bisa dibuka");
?>
and i had add this script on my.cnf file after [mysqld] =
bind-address=192.168.0.167
but it didnt work with the following caption
mycomputer.mshome.net is not allowed to connect to this Mysql server
Please help me.How to remote database mysql XAMPP from another computer ?
You will have to create a new user in MySQL that is allowed to connect from a remote host.
By default, root can only connect from localhost.
You could try running the following commands from the MySQL server (make sure to substitute 192.168.0.99 with the IP or hostname of the PC that will be connecting) In your case, try 'php'#'mycomputer.mshome.net' for the user:
CREATE USER 'php'#'192.168.0.99' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON dbbook.* TO 'php'#'192.168.0.99';
It is possible to specify a wildcard host ('php'#'%'), but then if anyone got your MySQL password they could connect to the DB. You could also wildcard your subnet ('php'#'192.168.0.%') which is a little safer.

Categories