0

I am using php to access a mysql database and have Safari render the php code. I have everything setup on my Mac running Mountain Lion. phpinfo() renders perfectly. If I use textmate and run the php code within phpmate, i can access the database and get the info I need. But when I access it within Safari, it displays the php code instead of connecting to the sql server and displaying the database.

THoughts/ideas ? I have apache working and i have mysql working. Queries to mysql using command line also work. Its just Safari that does not render the php code. Thanks.

<HTML>
 <HEAD>
  <TITLE> Our List of Link </TITLE>
  <HEAD>
   <BODY>
 <?php

  $dbcnx = $link = mysql_connect("localhost",'root','root');

  if (!$dbcnx) {
die(mysql_error());
  echo( "<P>Unable to connect to the " .
      "database server at this time.</P>" );
}

 if (! @mysql_select_db("UrlList") ) {
 echo( "<P>Unable to locate the  " .
      "database at this time.</P>" );
  exit();
}

 ?>
</BLOCKQUOTE>
</BODY>
 </HTML
1
  • 2
    Does the file have a .php extension? Is Apache configured with mod_php? Are you viewing the file using the server URL or the absolute file path? Commented Feb 10, 2013 at 4:43

2 Answers 2

1

It sounds to me like you need to set up the apache directory. When you open the php file in safari, are you just double clicking the file, or going to localhost/myfile.php? It is definitely a setup of apache to process the directory/file because currently it is not, safari is reading the file directly.

Sign up to request clarification or add additional context in comments.

Comments

0

had to rename the file to .php and it worked. Thanks again.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.