I'm in the process of setting up PHP / MYSQL on a Windows Server 2003 machine, with IIS. I have installed PHP 5.3.8 and MySQL 5.5. PHP is configured to use FastCGI.
In php.ini I have the following lines uncommented:
extension=php_mysql.dll
extension=php_mysqli.dll
Here is my code:
<?php
$con = mysql_connect("127.0.0.1","root","test");
if (!$con)
{
die('Could not connect: $php_errormsg' . mysql_errno() . ": " . mysql_error(). "\n");
}
echo "connected";
?>
Here is the output:
PHP Warning: mysql_connect(): in C:\Inetpub\wwwroot\mysqltest.php on line 2
I can connect to the MYSQL database on this server from a PHP page running on another webserver - so I know that my MYSQL database is correctly accepting connections.
Any help on this would be greatly appreciated
To view your connection error, you can print the output of mysql_error.
$con = mysql_connect("localhost","root","test") or die('cannot connect : '. mysql_error());
Apparently I had a permissions issue. I was able to resolve it by following these steps:
From Windows Explorer, I...
right-clicked on C:\Inetpub
went to Properties > Security > Permissions
selected "Replace permission entries on all child objects with entries shown here that apply to child objects"
clicked Apply
restarted IIS by running iisreset from a command prompt.
Related
This question already has answers here:
Warning: mysqli_connect(): (HY000/2002): No such file or directory
(6 answers)
Closed 2 years ago.
I am trying to connect to my MySQL server on a mac using PHP after starting the server using brew services start mysql After this I can see that the MySQL server has successfully started. However, when I try to access my webpage using:
<?php
/* Attempt to connect to MySQL database */
$link = mysqli_connect('localhost', 'root', 'password', 'databasename');
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
The webpage start spinning continuously and doesn't load. I was wondering what's the issue as I can log into the root from the command line as well as see the tables. And the bre shows MySQL server running in the background.
EDIT I managed to print my error however, now I get an error:
Warning: mysqli_connect(): (HY000/2002): No such file or directory However, homebrew shows my MySQL server running.
Try to change your host from localhost to 127.0.0.1
$link = mysqli_connect('127.0.0.1', 'root', 'password', 'databasename');
You better make sure if mysqli extension is available in php.ini
(If it is not enabled, go into the php.ini file and remove ; from the mysqli line.)
If mysqlit is enabled, try running the code below and restart the server/terminal php task if anything changes
cd /var mkdir mysql cd mysql ln -s /tmp/mysql.sock mysql.sock
Check your credentials you give into the mysqli_connect
If everything is okay, and you cant still connect try installing helpful programs like MAMP. They will create an Apache Server with Php and MySql server on local computer without a problem with full configuration
Playing with Openshift origin 3.9 on my custom servers. So far it has been a pleasant experience. I've been building a custom s2i image based on Ubuntu for my LEMP stack.
I'm not able to connect to the MySQL database. I always get an error saying:
Failed to connect to MySQL: (2002) No such file or directory
Here's my PHP code:
$mysql_database = getenv("MYSQL_DATABASE");
$mysql_server_name =getenv("MYSQL_HOST");
$mysql_username = getenv("MYSQL_USER");
$mysql_password = getenv("MYSQL_PASSWORD");
$mysql_port = getenv("MYSQL_PORT");
$mysqli = new mysqli($mysql_server_name, $mysql_username, $mysql_password, $mysql_database, $mysql_port);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
die();
}
Some observations:
I'm able to connect from MySQL CLI client from inside the pod.
The same app/code works fine with the official openshift PHP s2i image.
Am I missing anything in my s2i?
Check your phpinfo() and search for MySQLi extension. If you can't find, that means you do not have the extension installed yet and it needs to install.
try installing from terminal
(Ubuntu/Mint) $ sudo apt-get install php(version)-mysql
replace (version) with any of your php version number. For example, php7.0 / php7.1, etc.
To check phpinfo(), create a phpinfo.php file which you can access from url with the content
<?php
phpinfo()
If you have everything and still unable to connect? Try checking your mysql.sock file path.
Open the php.ini file and find this line:
mysql.default_socket
And make it (know where your mysql.sock located)
mysql.default_socket = /path/to/mysql.sock
I know questions related to this have been asked a zillion times on Stackoverflow and elsewhere, however, I can't seem to zero in on a resolution.
I am using a nearly fresh-out-of-the-box Macbook 13 running OS 10.13.6 High Sierra.
My goal is to create a development environment with MAMP such that I can create dynamic webpages and I'd like to use Tableau for analytics drawing data out of MySQL.
I have successfully installed and run MAMP - I have created a simple database using phpMyAdmin - and I have connected Tableau to this database successfully - this works very well.
With that in operation, I shifted my attention to trying to run php from my browser. Entering "localhost" yielded the "It works!" result.
All good so far but here is where things go off the rails: I cannot connect to MySQL via a php file using the following (****** = my root password) - filename: test_connect0.php:
<?php
$link = mysqli_connect("localhost", "root", "*****");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL ."<br>";
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL ."<br>";
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL ."<br>";
exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>
What returns from running Safari or Chrome - doesn't matter - is the familiar issue: 2002 No such file or directory.
BELIEVE ME, I have searched all over the internet for solutions and I believe I have tried each and everyone to no avail.
Here are a few things I have done:
Running phpInfo from MAMP returns the expected path to php.ini: /Applications/MAMP/bin/php/php7.2.1/conf
In that php.ini file, the mysqli.default_socket is /Applications/MAMP/tmp/mysql/mysql.sock and that file does indeed exist
Running phpInfo from MAMP indicates the php version is 7.2.1
In /etc/apache2, I edited httpd.conf and uncommented LoadModule php7_module libexec/apache2/libphp7.so
I have tried a number of different ways to run the test_connect0.php file: localhost/test_connect0.php localhost:3306/test_connect0.php 127.0.0.1/test_connect0.php 127.0.0.0/test_connect0.php
An observation: In item 3 above, I noted that phpInfo from MAMP returns 7.2.1 as the version. When I run a phpinfo() script from the browser, however, it returns 7.1.16. I can't explain why that's a different php version and I cannot even FIND version 7.1.16 on my machine AND I'm not sure any of that really matters.
To summarize, I have a functional MAMP and a functional Tableau connection to MAMP's MySQL. What I can't do is connect to MySQL from a php file run in the browser - I get the 2002 error.
What other information can I provide to help zero in on a solution?
I found the solution:
PHP script fix:
Originally, I had my test_connect0.php script in /Library/WebServer/Documents. It turns out, it needs to be in /Applications/MAMP/htdocs. Once I moved the file to that location, I entered this url into the browser: localhost:8888/test_connect0.php
That resulted in a successful connection to MAMP's MySQL.
Tableau notes:
As I noted earlier, I was able to connect Tableau to MySQL, however, it wasn't connecting to MAMP's MySQL. To shift Tableau to see MAMP's MySQL, I entered the following into Tableau's dialog:
Server: localhost
Port: 8888
Username: root
Password: ******
Two things are necessary ahead of time:
Install the OBDC drivers per Tableau's instructions
Run this in a terminal window: sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
I have this problem, i have created a php file which inserts data into a mysqldatabase on Mamp.
I can use the command mysql anywhere and it starts the mysql client.
But when i start my php script i get this error:
Warning: Error establishing mySQL database connection. Correct user/password? Correct hostname? Database server running? in
For testing i have used the default username and password "root". Anyone know what causes this?
I have also tried this command:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
For me it is working fine. Which hostname you are using in your php code?
sgeorge-mn:~ sgeorge$ cat con_mysql.php
<?php
$con = mysql_connect("127.0.0.1:3306","root","PASSWORD");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "Connection Established\n";
}
mysql_close($con);
?>
sgeorge-mn:~ sgeorge$ php con_mysql.php
Connection Established
I am new to PHP and MySQL and have recently installed both PHP v5.3.10 and MySQL v 5.5.21 on a Windows Server 2003 server already running IIS v6.
PHP runs and I have created a database on MySQL from the MySQL 5.5 Command Line Client.
However, when I try to access the database from PHP with the following commands:
echo "Open database";
$link = mysql_connect($host, $username, $password);
echo " link: $link";
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $link)or die("cannot select DB");
echo " database open";
I get the following returned to the web page:
Open database
No error messages are produced and nothing after the mysql_connect command is returned from
the PHP to the screen.
Also tried line below which also did not return any error messages:
mysql_connect($host, $username, $password) or die('Cannot connect:' . mysql_error());
Anybody have any ideas why I can't make a connection and can't get an error message back from mysql_connect command?
I have checked MySQL and I have tried defining the host as %, localhost, the local host IP and the IP:port number (from the port number 3306 listed in the my.ini) to no effect.
I only have one username of 'root' created in mySQL with a single password (which I used when I opened MySQL to create the database)
The 'php.ini' I have placed in both the 'C:\Program Files\PHP' and 'C:\WINDOWS'.
This file contains 'extension_dir = "C:\Program Files\PHP\ext"' to specify the extension directory and includes the following at the end of the file:
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
Also I tried running phpinfo() and it returned the following table for mysqlnd:
mysqlnd enabled
Version mysqlnd 5.0.8-dev - 20102224 - $Revision: 321634 $
Compression supported
SSL supported
Command buffer size 4096
Read buffer size 32768
Read timeout 31536000
Collecting statistics Yes
Collecting memory statistics No
Tracing n/a
So Is I assume the php should be able to connect.
Try this:
ini_set('display_errors',1);
error_reporting(E_ALL);
To mirror #Jrod:
is error_reporting on?
have you checked the error_log for the instance?
It sounds like something's failing and your error reporting isn't set high enough to show it. You might try addin this to the top of the script:
error_reporting(E_ALL);