SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Help with connecting to my database

  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with connecting to my database

    Hi, purchased 'build your own database driven website using php & mySQL'.


    Have gone through the book...set up mysql and php. Have followed the excercises and all work fine but when I get to the chapter inserting data into the database. Cannot get information from the databse displayed in my browser. Do not get any errors just blank screen in my browser. Any ideas guys?

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have data in my database

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Location
    Manchester UK
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have a fully working Table in your Database. And also show us the code in which you are connecting to the Database with.

    Then you can do something like this.

    PHP Code:
    <?

    mysql_pconnect
    ("Host Name Here","Username Here","Password Here");

    mysql_select_db("database Name Here");

    $result mysql_query("select * from `Table name`");

    ?>

    <?

    while($r=mysql_fetch_array($result)) {

    $field1 $r["field Name"];

    echo 
    "$field1";

    }
    ?>
    I hope this is what your looking for but also just check your information in PHPMyAdmin.

    Dan

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my php. not sure if my username is correct! Is there anyway I can check?

    <?php

    // Connect to the database server
    $dbcnx = @mysql_connect('localhost', 'root', 'stokecity');
    if (!$dbcnx) {
    exit('<p>Unable to connect to the ' .
    'database server at this time.</p>');
    }

    // Select the jokes database
    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable to locate the joke ' .
    'database at this time.</p>');
    }

    ?>
    <p>Here are all the jokes in our database/p>
    <blockquote>
    <?php

    // Request the text of all the jokes
    $result = @mysql_query('SELECT joketext FROM joke');
    if (!$result) {
    exit('<p>Error performing query: ' . mysql_error() . '</p>');
    }

    // Display the text of each joke in a paragraph
    while ($row = mysql_fetch_array($result)) {
    echo '<p>' . $row['joketext'] . '</p>';
    }

    ?>

  5. #5
    I Never Give Up roosevelt's Avatar
    Join Date
    May 2005
    Posts
    504
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you make the database using PHPmyAdmin or MySQL Console on your web server? The user root should be able to connect if you got your password right.

  6. #6
    Non-Member jake4974's Avatar
    Join Date
    Jan 2006
    Location
    Down the road, it's where I'll always be
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you were trying to connect with an incorrect username you would get an "Acess denied" error.
    A totally blank screen usually indicates an error with your syntax in your PHP.
    The thing is, I see no errors in your syntax. So:
    either it's a syntax error I just don't see or
    it's some other kind of error I'm unfamiliar with and I can't help

  7. #7
    Twitter - @CarlBeckel busy's Avatar
    Join Date
    May 2004
    Location
    Richmond, VA, USA
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try your username and password to log in via the command line client. If they work there, then that's not the problem.

    You should remove the @ signs from your code, because they supress error messages, and you might get a hint at what's wrong.

    What version PHP and MySQL do you have? I just upgraded to version 5 of both of them and had an obscure connection problem that required changing the my.ini file to get it to work.

    You can also add
    Code:
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', TRUE);
    to the top of your script to turn on all errors (you still have to remove the @ signs)

    If it helps, a few people were having a similar issue over here:
    http://www.sitepoint.com/forums/show...50#post2512550

    (If you get an error message, be sure to post it here)

  8. #8
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    using mysql 5 and php 5.

    Have been looking into this problem and have discovered that the issue could be down to connection problems with php and mysql. Have discovered that I need to download MySQLStartupItem.pkg to fix this problem.

    Anyone done this before??

  9. #9
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have followed the instructions to install the extensions etc. still getting a blank screen.

    So have decided to take the @ signs out of the code to see what error I get.....and get the following error:
    Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\wwwroot\jokelist.php on line 11


    line 11 of my code is
    $dbcnx = mysql_connect('localhost', 'root', 'stokecity');
    I am wondering if my username is correct.....def know password is correct because i can log into mysql. How can I find my username????? Can I reset them?? Is the username always 'root'??

    Hope someone can help.

    cheers guys

  10. #10
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cambs, UK
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Silly question but is php_mysql.dll enabled in your php.ini?
    Jo

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •