SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no connection to joke database

    i have tryed to connect to the database but it is saying Unable to locate the joke database.

    bit the database ijdb is there as is joke any one know why this is happening
    the joke as jokes in it ect but ive tryed everythin i can think of i am new to php my sql but it wa working then it as stoped i have the right details in the connect index.php page which is below i do not use password because im just learning, anyone can help please send me email or you can contact me on skype or msn or yahoo all help will be greatful thanks paul
    here is my code

    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost''ijdb''');
    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';
    ?>
    Last edited by SpacePhoenix; Feb 22, 2011 at 08:23. Reason: put php tags round php code to improve readability

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    As a debug test:
    PHP Code:
    $link mysqli_connect('localhost''ijdb''') or die(mysql_error()); 
    see what it says.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ View Post
    As a debug test:
    PHP Code:
    $link mysqli_connect('localhost''ijdb''') or die(mysql_error()); 
    see what it says.
    thankyou for your repley but im still getting the same error
    Unable to locate the joke database.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    After the if block for connecting to the MySQL server, add this line

    PHP Code:
    printf("Server version: %s\n"mysqli_get_server_info($link)); 
    If PHP has connected to MySQL ok then the server version will be displayed, if the server version isn't displayed or has an error then the problem is with establishing a connection between PHP and MySQL
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    After the if block for connecting to the MySQL server, add this line

    PHP Code:
    printf("Server version: %s\n"mysqli_get_server_info($link)); 
    If PHP has connected to MySQL ok then the server version will be displayed, if the server version isn't displayed or has an error then the problem is with establishing a connection between PHP and MySQL
    thanks for your reply but it still same error unless i have put it in the wrong place here is the code ive more than likely put it in the wrong place thanks again here is the code?

    <?php
    $link = mysqli_connect('localhost', 'ijdb', '') or die(mysql_error());

    if (!$link)

    {printf("Server version: %s\n", mysqli_get_server_info($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';
    ?>

  6. #6
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello i have changed my database name to somthing else and the joke table what i am getting now it is trying to download a file instead of showing the jokes woulda anyone have any ideas why (started getting to me now doin everything in book to the letter and it still isnt working)
    thankyou for reading this and i hope you can help ?

  7. #7
    SitePoint Zealot Ethan-27's Avatar
    Join Date
    Jan 2011
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you checked your password to the database...? There might be one set and you will need to set it to no password if you dont want one

    Are you using a localserver with phpmyadmin...?

    Also try removing the $link variable in your 'select _db' line, it might make a difference

    This is the code I use, it might help.



    <?php

    $connect = mysql_connect("localhost","root","")
    or die ("Connection failed");

    mysql_select_db("phppractice") or die ("Nope didn't connect");
    echo "Connected";



    ?>

  8. #8
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    From your first post you said

    i have tryed to connect to the database but it is saying Unable to locate the joke database.

    bit the database ijdb is there as is joke any one know why this is happening
    from this I read that your database table is called "joke" not 'ijdb'

    So you need to change line 17

    PHP Code:
    if (!mysqli_select_db($link'ijdb')) 
    to

    PHP Code:
    if (!mysqli_select_db($link'joke')) 
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  9. #9
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thankypu for your help with my problem but i am still getting the same error it is trying to download the file instead of showing joes in the data base
    i am not using a password and i am using localhost on my computer
    here is the code i have got:
    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost''bailuk''');
    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'bailsjokes'))
    {
    $output 'Unable to locate the bailsjokes database.';
    include 
    'output.html.php';
    exit();
    }
    $output 'Database connection established.';
    include 
    'output.html.php';
    ?>
    i have attached a screen shot of the erro to download
    thank you again for all your help
    Attached Images Attached Images
    Last edited by SpacePhoenix; Feb 26, 2011 at 15:43. Reason: put php tags round php code to improve readability

  10. #10
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    attachments take too long to be approved, please copy and paste what error you are now getting
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  11. #11
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the error i am sorry i can not get it to paste into box i have trye all extentios gif jpeg ect

  12. #12
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I just need to know which error you are seeing on your screen now, you have changed the name of your database and the name of your table, I cant just assume that youre still getting the error in the same part of your code.

    You can send me the attachment via PM if you want
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  13. #13
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    Add this between the block where the character set is set and the block where a database is selected:

    PHP Code:
    $db_list mysql_list_dbs($link);

    while (
    $row mysql_fetch_object($db_list)) {
         echo 
    $row->Database "<br />";

    That should display a list of databases on the server which the current MySQL user is allowed to see. You should see amongst the list of databases the 'ijdb' (or whatever you named the jokes database) database listed there.

    If it is not listed then it may be that the MySQL user your using to log into MySQL from PHP might not have the rights to see the jokes database.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  14. #14
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you all for trying to help me i still can not connect to the database joke i have reinstalled everything and set new passwor but im still getting this error:
    UNABLE TO CONNECT TO THE DATABASE SERVER.

    the password is 100% correct i have followed every step of the book a million times and it is all correct to the book and still will not connect here is the code im using i have added the @ at the top line to stop load of text coming before the error thanks again for all your help

    <?php
    $link = @mysqli_connect('localhost', 'ijdb', 'bailukcom');
    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';
    ?>

    wish i could get this sorted stoping me movin to next chapter!!!!!!

  15. #15
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $link = @mysqli_connect('localhost''ijdb''bailukcom'); 
    So 'ijbd' is your sql database name (not to be confused with table name) and 'bailukcom' is your sql password, yes ?

    replace this line

    PHP Code:
    $output 'UNABLE TO CONNECT TO THE DATABASE SERVER.'
    with

    PHP Code:
     $output 'UNABLE TO CONNECT TO THE DATABASE SERVER. - ' mysqli_error(); 
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  16. #16
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    just a thought have you tried not using the mysqli extension, perhaps it not enabled.

    Try this

    PHP Code:
    <?php
    $link 
    = @mysql_connect('localhost''ijdb''bailukcom');
    if (!
    $link)
     
    {
    $output 'UNABLE TO CONNECT TO THE DATABASE SERVER. - ' mysql_error();  
    include 
    'output.html.php';
    exit();
    }
     
    if (!
    mysql_set_charset($link'utf8'))
     
    {
    $output 'UNABLE TO SET DATABASE CONNECTION ENCODING. - ' mysql_error();  
    include 
    'output.html.php';
    exit();
    }
     
    if (!
    mysql_select_db($link'ijdb'))
     
    {
    $output 'UNABLE TO LOCATE THE JOKE DATABASE. - ' mysql_error();  
    include 
    'output.html.php';
    exit();
    }
     
    $output 'DATABASE CONNECTION EStABLISHED.;
    include '
    output.html.php';
    ?>
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  17. #17
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your reply i have changed what you said and now i get diffrent error
    Fatal error: Call to undefined function mysql_error() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 6
    now i get that and here is the line you told me to change
    PHP Code:
    <?php
    $link 
    = @mysqli_connect('localhost''ijdb''bailukcom');
    if (!
    $link)

    {
    $output 'UNABLE TO CONNECT TO THE DATABASE SERVER.' mysql_error();

    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';
    ?>
    thanks again?
    Last edited by SpacePhoenix; Mar 7, 2011 at 13:17. Reason: put php tags round php code to improve readability

  18. #18
    SitePoint Zealot Ethan-27's Avatar
    Join Date
    Jan 2011
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like a configuration problem with your locahost software.

    Are you using WAMP....? This would really help if you tell us what software you are using for this.

    If so make sure rewrite_module is turned on, this caused me problems before.

    You do this by going to WAMP, right clicking, going to Apache, going to Apache Modules, then scrolling down the list and getting a tick placed next to the mentioned above.

    I know this is small point but the name of your db is exactly the same as the one in your script right....?

  19. #19
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no i am using the windows essentails (x86) and apache 2.2.15 (win32) and php 2.2.13 as it says in the book i installed the idivdule package ones, i am using windows 7 ulitmate as my o/s, all datbase everything is workin it is allowed through windows fire wall just that it will not connect for some silly reason
    thankyou for your reply

  20. #20
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thankyou all for yur help i have sorted it it as connected to the db now thank you all

  21. #21
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bail View Post
    thankyou all for yur help i have sorted it it as connected to the db now thank you all
    And for our info, the problem was ?
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  22. #22
    SitePoint Enthusiast bail's Avatar
    Join Date
    Feb 2010
    Location
    walsall westmidlands
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    from this

    $link = @mysqli_connect('localhost', 'ijdb', 'bailukcom');

    to this

    $link = @mysqli_connect('localhost', 'root', 'bailukcom');

    thankyou all once again we all got learn some were haa
    take care you might seeing me in here quite oftern !!!


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
  •