php and mysql connect issues on windows server / IIS6 - php

I installed php and mysql on a Windows 2003 server running IIS6. I uncommented the lines for the mysql and mysqli extensions. I am able to run phpinfo, and am seeing the mysql and mysqli sections in phpinfo.
I then run the following code to attempt a connection to the database -
<?php
$link = mysql_connect('localhost', 'root', 'mypassword');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
When I attempt to load this through a browser, I am getting a generic 500 server error. I don't know where else to look to troubleshoot this issue. Can someone point me in the right direction?
I am also able to access the mysql database using mysql workbench on the server.
Thanks for any thoughts.

I solved this by referring to this post - PHP has encountered an Access Violation at 77FCAFF8
Ultimately, I uninstalled MySql and then reinstalled at the root of my filesystem in order to eliminate any spaces in the path. I then recycled my application pools, and am now able to connect.
thanks.

Related

PHP - Mysql: can't connect to database

I've setup mysql server 8.0, Apache2.4, php 7.2 and created a simple database.
As a start I am trying to write a php code for connecting to the database but i can't figure it out.
My code:
<?php
$con = mysqli_connect("localhost","Don","password","db1");
if (!$con) {
echo "Error: " . mysqli_connect_error();
exit();
}
echo 'Connected to MySQL';
?>
I get Error: The server requested authentication method unknown to the client.
I've tried several things: connect to root, 192.168.0.1 instead of localhost but nothing is working.
Any ideas? Thanks.
(post for someone who has the same problem)
i searched about the old password issue but i couldnt find the old_passwords var, not even in my.cnf file.
so what i did was uninstalling mysql server 8.0 and installing 5.7.2 and it worked.
ps i didnt configure anything differently while setting up the 5.7.2 version.

php mysql connect fails even though shell client succeeds

I have a weird problem.
I'm trying to connect from a linux host to a remote MySQL server on a Windows host.
If I try to connect from shell using the mysql client it works perfectly.
#mysql -h 192.168.x.x -u MyUser -pMyPassword
I've also tried connecting from a simple python script and it works as well.
But if I try to connect from a php script it fails with a "Can't connect to MySQL server on '192.168.x.x' (13)" error.
mysql_connect ('192.168.x.x', 'MyUser', 'MyPassword');
the remote server is running 5.0.41-community-nt on Windows (no info about the OS version)
the client machine is running CentOS 6.2 and is itself equipped with a MySQL 5.1.61 server.
The PHP MySQL module is using the sampe API version 5.1.61
The problem MUST be inside PHP as the connection is successful from the shell client (and even from a python script) but I don't have a clue.
Any help will be higly appreciated.
Use the simple PHP way to connect MySQL:
<?php
$link = mysql_connect('192.168.x.x', 'MyUser', 'MyPassword');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Please, show us the full code.

PHP, MySQL, Lost connection to MySQL server during query, TurnKey Ubuntu/Linux,

Hi to all php and mysql experts,
I try to find some help or 'tutorial' or similar question/answer for my problem but it was unsuccessful.
I have install TurnKey Linux, php, mysql, successfuly width ip address: 172.##.##.## and I can connect to this server from another comp.
I was edit my my.cnf file, I was open port 3306 and I can connect via mysql -u root -p -h 172.##.##.## from another comp. I was add user:root that can connect from any host or IP address. Also I can make successful connections width mysqladmin or mysql workbench.
I can, also, make database and some tables on this server like db_test, tab_test etc. and if I use next script on this server its work very good:
<?php
$db_hostname="localhost";
$db_username="root";
$db_password="pxxxxx";
$db_connect=mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_connect) {
die('Could not connect: ' . mysql_error());
}
mysql_close($db_connect);
?>
But if I use next script it does not work and report to me error: Could not connect: Lost connection to MySQL server during query;
<?php
$db_hostname="172.##.##.##";
$db_username="root";
$db_password="pxxxxx";
$db_connect=mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_connect) {
die('Could not connect: ' . mysql_error());
}
mysql_close($db_connect);
?>
Also this script it does not work if I use another php server witch can see or ping this server.
Can somebody help me to resolve this problem! Please. I am desperate.
I have the same error, please go to xampp\phpMyAdmin\libraries\config.default.php
Modify the following code
existing one - $cfg['ExecTimeLimit'] = 300;
modify to - $cfg['ExecTimeLimit'] = 600;
This is getting a bit long for a comment....
It doesn't appear to be a connection error - that's a different error message.
Changing the configuration of PHPMyAdmin is not going to make any difference to other scripts.
It might help if you publish details of the mysql config from PHP. Also is your mysqld started with skip-name-resolve? How long does your example script take to fail?
One thing to watch for is that when the mysql client sees 'localhost' in the conection string, it tries to connect via a filesystem socket - not a network socket - do you get the same error when you supply the host as 172.##.##.## ?

MySQL failing to establish a connection using PHP

Using ubuntu 12.04 64 bit on Lenovo t410.
Using apache2 and Mysql 5.5 and attempting to connect via localhost
I am attempting to establish a connection to a database that I made on localhost. When the line of code is reached to establish a connection, it seems Mysql simply hangs, and there is no error message displayed after. I verified that an echo works immediately prior to the connection attempt. I know that apache2 server is working as I can access the index page and display my html form.
I have tried etc/mysql/my.cnf setting the bind address to localhost.
My line of code looks like:
// Attempts to establish connection to MySql server
$connection = mysql_connect("localhost","username","password");
// Prints error message if the connection to MySql fails
if (!$connection){
die("Connection failed: " . mysql_error());
}
echo "Connection established.";
I tried the connection line with single quotes and with no semi-colon as well.
I am willing to post the contents of any configuration file I have if the error isn't syntax. I haven't done anything fancy to Ubuntu, everything is the default install. I am new to CS and especially databases, PHP, and networking. This is my little experiment that I am stuck on.
Any help is greatly appreciated. Thanks,
Don
Can it be, because there is no error message, that the connection IS established, but you didn't do anything with it?
I mean, what is the rest of your code, is there after your code here something like:
mysql_select_db("database_name",$connection);
After reading your last comment, it appears the mysql extensions are not being loaded. Have a look at your php.ini, uncomment the following line (remove the semicolon at the beginning of the line) and restart your apache:
extension=php_mysql.so
Make sure the extension exists in the php extensions directory.
Due to the fact that you are using MySQL version > 4.1.3 it is strongly recommended that you use the mysqli extension instead. Have a look at this: PHP: MySQL Overview
try to set
$mysql_user = "your_username";
$mysql_pass = "your_password";
$mysql_server = "Servername";
$link = mysql_connect($mysql_server,$mysql_user,$mysql_pass);
if (!$link) {
header('HTTP/1.1 500');
exit();

Apache 2.2 Mysql and PHP connection failed (Windows)

My current situation is that I'm using:
1) Mysql Version 5.1
2) Apache Server 2.2
3) Php Version 5.2.17
And... I have the simplest PHP Code Here.
But poorly, the connection is always failed (On Browser). I tried to follow some steps from the StackOverFlow, and also some other forums such as here;
I already tried to:
1) Ensure the System32\drivers\etc\host file is using the safe
Host File Content Here.
2) Ensure the Apache is having Safe Error Content Here.
3) Ensure the mysqli & mysql extension of PHP is Installed
properly accordingly.
But then... The latest result is still same, problem still exist. Sigh. Is there something I forgotten?
if you are using Windows 7 then you need to change localhost to 127.0.0.1.
Is the database running? You need to check that it is started by going to the MySQL bin directory and running mysql command (if you are requested for a password, just hit enter). If you connect then the user is root and the password is blank
What username and password are you using to access the database?
Why are you using #mysql_connect? remove the "#" symbol
<?php
$url = 'localhost';
$link = mysql_connect($url, 'user', 'pass');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

Categories