Please be patient with me as I try to explain my problem, I’m a total newb to all of this. I could really use some assistance on this as I have searched for days trying to find the answer and have failed to find the answer.
The setup you need to know:
Apache Server is installed and up and running fine
MySql service is running
I can use mysql through command console to see my DB and tables
I’m running on Windows XP Media Edition
What’s happenning:
As I work my way through the tutorials in the SitePoint Book titled “Build your own Database Driven Web Site, Using PHP and MySQL” everything worked fine; installation of Apache, installation of MySQL, and even the chapters on adding tables…etc. The problem occurs when I get to the part where I have to connect to MySql through PHP.
When I type http://localhost:8080/test/chapter4/connect and hit enter in the browser I get nothing…ziltch…nada…If I view source it’s empty. I’ve tried variations of connections and still I’m getting nothing. HALP! what am I doing wrong? For those of you familiar with the book I’m stuck on page 121.
I suspect the problem is something related to the root of mySql but I haven’t been able to figure out what. Is there something I have to do with mySql to tell it the root?
Two files (located at htdocs/test/chapter4/connect)
the scripts:
index.php
<?php
$link = mysqli_connect('localhost:8080', 'root', 'testpassword');
if (!$link)
{
$output = 'Unable to connect to the database server.';
include 'output.html.php';
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Unable to set database connection encoding.';
include 'output.html.php';
exit();
}
if (!mysqli_select_db($link, 'ijdb'))
{
$output = 'Unable to locate the joke database.';
include 'output.html.php';
exit();
}
$output = 'Database connection established.';
include 'output.html.php';
?>
Sgtlegend…I understand what you’re saying and changed locahost:8080 to localhost in the PHP code and still I get nothing…I don’t even get the error messages for not making a connection.
Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ est\chapter4\connect\index.php on line 5
Code that displayed error:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$link = mysqli_connect('localhost', 'root', 'testpassword', null, 8080);
if (!$link)
{
$output = 'Unable to connect to the database server.';
include 'output.html.php';
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Unable to set database connection encoding.';
include 'output.html.php';
exit();
}
if (!mysqli_select_db($link, 'ijdb'))
{
$output = 'Unable to locate the joke database.';
include 'output.html.php';
exit();
}
$output = 'Database connection established.';
include 'output.html.php';
?>
are sure that the mysql server is running on port 8080?
the default port for mysql is 3306
usually, the 8080 port is used when the 80 is blocked by isp
it is running on 3306…so how do I change it? The book says nothing about having to change the port your MySql uses. Did the author forget to mention that critical piece of information?
Ok…here’s the deal
I was anticipating the future installation of IIS to learn ASP and told apache to use port 8080. So if my mySql is using port 3306 and Apache is using 8080 is there something not communicating? I’m referencing my PHP pages at http://localhost:8080/… do I need to change something so I can get connected to the MySql database server?
I’ve had all sorts of problems when i was setting this up originally. I think what worked for me was making sure i was running the text editor as ‘admin’. i think anything else saved int he htdocs floder just isnt visible.
So open your text editor with ‘run as administrator’ and do exactly what it says in the book.
Well…I have no idea what the author is trying to teach us by having us install Apache, SQL and PHP separately…I finally gave up on his approach, uninstalled everything, downloaded XAMP, installed PHP, MySql, and Apache. Then I went back and rebuilt the database using their WYSIWYG editor and made my connection to the mySQL database in about five minutes. At least now I can proceeed to the next part of the book…learning PHP. I guess I’ll just have to forgoe the parts on using mySQL admin through the cmd cosole and modify my tables through XAMPs MySql Admin/Editor. I can’t seem to pull up anything using mysql through a command line console.
so…I’ve got it working with the exact same code from above. All I did was uninstall everything the book told me to do and downloaded XAMP and installed PHP, MySql, and Apache with their package installer. It also provides a much more user friend interface for me to interact with the applications/servers.