PHP MySQL Connect Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yes_its_just_me@yahoo.com

    PHP MySQL Connect Problem

    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_emai ls and show the results
    of a table called newsletter_memb ers. Any help would be appreciated.
    Thanks, Josh.

    <?php

    /* Connect to the MySQL server */
    $mysqli = new mysqli('localho st', 'josh', '******',
    'newsletter_ema ils');

    /* Check connection */
    if(mysqli_conne ct_errno()) {
    printf("Error: Could not connect to MySQL Server. Please try again
    later. Errorcode: %s\n", mysqli_connect_ error());
    exit();
    }

    /* Send the query to the server */
    if($result = mysqli->query('SELEC T * FROM newsletter_memb ers')) {

    print("Contents :\n");

    /* 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 */
    $result->close();
    }

    /* Close the connection */
    $mysqli->close();

    ?>

  • adlerweb

    #2
    Re: PHP MySQL Connect Problem

    phyes_its_just_ me@yahoo.com schrieb:
    When I execute the script it does nothing, no
    error messages, nothing.
    Hello
    Insert error_reporting (E_ALL); on top and try again.
    adlerweb

    Comment

    • seaside

      #3
      Re: PHP MySQL Connect Problem


      yes_its_just_me @yahoo.com schrieb:
      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.
      You might wish to give PHPDebugger a try, since its
      'TADebugger.inc .php' automatically switches to highest error mode and
      redirects all error/exception output to PHPDebugger [does not disrupt
      your HTML code]:

      OS X: http://www.turingart.com/downloads/phpDebugger.zip
      Windows: http://www.turingart.com/downloads/phpDebuggerWin.zip

      Info: http://www.turingart.com/downloads/p...esentation.pdf

      Comment

      • Ian M Robertson

        #4
        Re: PHP MySQL Connect Problem

        yes_its_just_me @yahoo.com wrote:
        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_emai ls and show the results
        of a table called newsletter_memb ers. Any help would be appreciated.
        Thanks, Josh.
        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
        problem

        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
        IanR

        --
        homepage http://narian.org.uk

        Comment

        Working...