I'm on Windows and I'm trying to connect to a mysql database from php.
This is the code of the php file:
<?php
echo "Hello World!";
$link = mysql_connect('127.0.0.1:3306', 'root', '1234');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
When I run the php file on Apache server instead of getting a successful message I get a blank page.
I've tried with "localhost" instead of "127.0.0.1" but I got the same result.
What can I do?
thanks.
if you are using latest version of php then, mysql is deprecated so you're better off using mysqli.
<?php
echo "Hello World!";
$link = mysqli_connect('127.0.0.1:3306', 'root', '1234');
if (!$link) {
die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.