PHP MySQL Connect Problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone, I haven't used PHP since version 4 and am trying to use it
for a new project. All I'm trying to do is connect to a MySQL database
and show the contents of that database (as a start). However, nothing
seems to be working. When I execute the script it does nothing, no
error messages, nothing. I know that PHP is working because I've done
the phpinfo(); thing and it works. I also know my database is working
because I can access it from the command line and do whatever I want
with it. So for some reason I'm not able to connect to it from PHP, but
since I'm not getting any errors I have no clue what's wrong. I've
included my code below. This is all set within the body tag. I'm trying
to connect to a database called newsletter_emails and show the results
of a table called newsletter_members. Any help would be appreciated.
Thanks, Josh.


  /* Connect to the MySQL server */
  $mysqli = new mysqli('localhost', 'josh', '******',

  /* Check connection */
  if(mysqli_connect_errno()) {
    printf("Error: Could not connect to MySQL Server. Please try again
later. Errorcode: %s\n", mysqli_connect_error());

  /* Send the query to the server */
  if($result = mysqli->query('SELECT * FROM newsletter_members')) {


    /* Fetch the results of the query */
    while( $row = $result->fetch_assoc() ) {
      printf("%s\n", $row['email_addr'], $row['contact_type']);

    /* Destroy the result set and free the memory used for it */

  /* Close the connection */


Re: PHP MySQL Connect Problem schrieb:
Quoted text here. Click to load it

Insert error_reporting(E_ALL); on top and try again.

Re: PHP MySQL Connect Problem schrieb:

Quoted text here. Click to load it

You might wish to give PHPDebugger a try, since its
'' automatically switches to highest error mode and
redirects all error/exception output to PHPDebugger [does not disrupt
your HTML code]:



Re: PHP MySQL Connect Problem wrote:

Quoted text here. Click to load it

Could be a number of things - ( eg perhaps selinux is preventing php from
contacting mysql - had that problem on fedora - disable selinux to check )

So would be usefull to know what platform you are on. As the others have
posted some debug info would be helpfull - have a look
in /var/log/httpd/error_log ( on most unix ) that may give some idea of the

Do you have the mysql component of php installed . With php5 the mysql lib
is not bundled ( unlike php4 )

Hope this gives you some pointers


Site Timeline