SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with connection to mysql database by PHP

    Hi. I'm totally new to this kind of things, but I bought a Kevin Yank Book about PHP/mysql and started to rock.

    I was doing everything on my own, but this stuff is just too hard for a beginner.
    I looked everywhere trying to solve it on my own, but sorry I must ask you.

    I have problem with connection to my sql database.

    Codes:

    Index.php :

    PHP Code:
    <?php
    $link 
    mysqli_connect('localhost''root''xxxxxx');
    if (!
    $link)
    {
       
    $output 'Nie można się połłączyć z serwerem bazy danych.';
       include 
    'output.html.php';
       exit();
    }

    if (!
    mysqli_set_charset($link'utf8'))
    {
       
    $output 'Nie można ustanowić kodowania dla połączenia z bazą danych.';
       include 
    'output.html.php';
       exit();
    }

    if (!
    mysqli_select_db($link'ijdb'))
    {
       
    $output 'Nie znaleziono bazy danych ijdb.';
       include 
    'output.html.php';
       exit();
    }

    $output 'Nawiązano połączenie z bazą danych.';
    include 
    'output.html.php';

    ?>

    and output.html.php :

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
    <HEAD>
      <TITLE>Dane wynikowe PHP</TITLE>
      <meta http-equiv="content-type" content="text/html: charset=utf-8"/>
    </HEAD>
    <BODY>
    <P>
    <?php echo $output?>

    </P>
    </BODY>
    I think there are no errors in this code, but when I'm launching localhost/connect/index.php it's just nothing on the Firefox and on the IE it looks like this: Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\Index.php on line 2 ..... it's after 2 hours of thinking, first it was just error 500. Apache 2.2.16 is running, PHP 5.2.14 installed and mysql serwer on, checked it with Mysql administator.

    Can someone help me?

    //sorry for my English, I'm Polish but doing my best.
    Last edited by SpacePhoenix; Jan 7, 2011 at 01:28. Reason: placed php tags around the php code (+ edited out password)

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This is really one for the PHP forum, I think. But wait in case someone knows the answer.

    It didn't work on my test set-up either, but I got
    Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2003): Can't connect to MySQL server on 'localhost' (10061) in .... line2
    Nie mozna sie pollaczyc z serwerem bazy danych.

    (Unable to connect to the database server. - google says its polaczyc not pollaczyc)

    However, when I included in the mysqli_connect(.....) my database name and the port number 3307, and set the select_db to my database, I got
    Nawiazano polaczenie z baza danych.

    (I'm connected to the database.)

    I don't like the OO approach, so I can't be sure why yours fails.

    Try running phpinfo() and check that mysqli is listed as running or installed or whatever the word is.

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,903
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    narvany, run this script:

    PHP Code:
    <?php phpinfo(); ?>
    Look for "Loaded Configuration File" and open that file in Notepad. Look out in that file for two lines:

    extension=php_mysqli.dll
    extension=php_mysqli.dll
    If either of them two lines have a ; in front of them then remove the ; and save the file. Then you'll need to restart the server.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2010
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On Windows, when you install newer versions of PHP, you're going to lack mysql_* functions.
    The reason for this is because lib_mysql.dll isn't being loaded as mysqli is considered as more secure and advanced interface towards mysql. So, mysql_ functions have been left out. You'll need to copy lib_mysql.dll to your windows/system32 folder if I'm not mistaken and do the things SpacePhoenix mentioned. I might be wrong since it's been a few years since I've done this, but a bit of googling might help.

    Note: if you're doing this on another OS, then I'm absolutely making a wrong guess so I apologize

  5. #5
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Big thanks to all of you, problem is solved. There was nothing wrong with code, it was something wrong with instalation of apache and php, probably mysql modules. Re-installing helped.


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
  •