简体   繁体   中英

How to know PHP is set-up correctly for Apache on localhost?

I am trying to retrieve data from MySQL for a flash application via PHP, but I am having trouble connecting to the server. I created the following.php to test whether it is functioning correctly:

<html>
<body>

<?php
$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

if (mysql_query("CREATE DATABASE testphp",$link))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  }
?>

</body>
</html>

When I try and access this from my browser I don't get anything back, it just remains blank? (when I just do localhost/xxx.php is just displays the code, don't know if that's helpful? -aside from entering file path) I tried some other.php files, but I either just get an error back or white web browser screen, as above? How can I test to see whether PHP is setup correctly? I know for sure it is working when I login using the mysql shell and do "show databases;" and testphp is listed, it is currently not. Thanks!

SOLUTION:

Turns out that I had been using the installer while I think there were a lot of assumptions that I was using binaries (or vice versa). Anyhow I have it up and running...expletive, expletive: :) Thanks everyone!

put the following script somewhere within your document root. Then go to that address it should print out a lot of useful information.

<?php
  phpinfo();
?>

Your problem is obviously (from the comments) that of a web server setting: you php pages are not being processed.

Try instead this

<html><body>
Hi
<br>
<?php
  echo "This line comes from php";
?>
<br>
Bye
</body></html>

When you see three lines in your browser, then you know that you PHP pages are being processed. After then, try the phpinfo() and only after then try to connect to the database. Step by step...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM