1

I have a Linux server with:

  • MySQL 5.1.57
  • PHP 5.1.6

When I try to connect MySQL- The output is a blank page.

The code is attached.

<?php
$link = mysql_connect("localhost", "usr", "pass");
if (!$link) {
    die("Could not connect: " . mysql_error());
}
print "Connected successfully";
Martin Prikryl
  • 147,050
  • 42
  • 335
  • 704
  • 3
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Apr 09 '14 at 08:54
  • View the source code of the page in your browser. Is it still blank? What does your server access log say? Is it getting the request for the page? What does your server error log say? Are there any errors? – Quentin Apr 09 '14 at 08:55
  • 1
    PHP 5.1 is no longer supported. **Do not use it**. Upgrade to a current version of PHP like 5.5.11. – Quentin Apr 09 '14 at 08:56
  • No errors in the log file. – user3485339 Apr 09 '14 at 09:17
  • What about the other three questions I asked? – Quentin Apr 09 '14 at 09:19

2 Answers2

0

Btw do you enable mysql module for php? You can check with this command

php -i | grep mysql

or see in web

<?php phpinfo(); ?>

And check PHP error log.

Valentin Hristov
  • 184
  • 1
  • 2
  • 9
-1

Most likely you don't have the php_mysql extension installed, so it doesn't understand what you're trying to do. To be sure about that, check your web servers error log. It should tell you why it didn't parse the page.

But as Quentin already mentioned in the comments, the mysql extension has been deprecated for quite a while now. Try installing the MySQLi or PDO extension and use that instead. PDO is more flexible and offers prepared statements support, so I'd suggest that.

So, install the PDO extension on your server (see the documentation for more details). And then connect using something like this instead:

$dbh = new PDO('mysql:host=localhost;dbname=test', 'user', 'pass');

This will connect you to the test database on your localhost. More information can be found in the PHP docs here.

Oldskool
  • 32,791
  • 7
  • 50
  • 64