CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Question PHP - MySQL interface problems

    I'm trying to address two (seemingly related) problems:

    o Getting phpMyAdmin to work
    o Access MySQL (v.5.0) from a PHP (v.5.1.6) script

    Getting phpMyAdmin to work
    ------------------------------------
    I installed the english.zip file from http://www.phpmyadmin.net/home_page/downloads.php. When I attempt to access phpMyAdmin I get an error page with the message: "Cannot load mysql extension. Please check your PHP configuration" and routes me to localhost/phpMyAdmin/Documentation.html#faqmysql. So, from this page,
    I'm concluding that I need the php_mysql.dll extension. In an effort to
    be totally current, I'm trying to use the MySQL Improved Extension.

    Investigating this extension, I read the following from
    http://us3.php.net/manual/en/ref.mysqli.php:

    "In order to have these functions available, you must compile PHP with
    support for the mysqli extension."

    How do I go about this? I don't have a compiler. I do have the .dll
    currently in C:\php\ext\.

    FYI, there are the PHP extensions I've enabled in Windows\php.ini:
    extension=php_gd2.dll
    extension=php_mysql.dll
    extension=php_mysqli.dll
    extension=php_xsl.dll

    Access MySQL (v.5.0) from a PHP (v.5.1.6) script
    --------------------------------------------------------------
    I ran the following code:
    <?php
    // defines database connection data
    define('DB_HOST', 'localhost');
    define('DB_USER', 'ajaxuser');
    define('DB_PASSWORD', 'practical');
    define('DB_DATABASE', 'ajax');
    // connect to the database
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
    // the SQL query to execute
    $query = 'SELECT user_id, user_name FROM users';
    //execute the query
    $result = $mysqli->query($query);
    // loop through the results
    while ($row = $result->fetch_array(MYSQLI_ASSOC))
    {
    // extract user id and name
    $user_id = $row['user_id'];
    $user_name = $row['user_name'];
    // do somthing with the data (here we output it)
    echo 'Name of user #' . $user_id . ' is ' . $user_name . '<br/>';
    }
    // close the input stream
    $result->close();
    // close the database connection
    $mysqli->close();
    ?>

    I get the following message suggesting that it can't find the mysqli class:
    "Fatal error: Class 'mysqli' not found in C:\Apache\htdocs\ajax\foundations\mysql\index.php on line 13" ($mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

    As I said above, I have the following in php.ini:
    extension=php_mysqli.dll

    I have php_mysqli.dll in php\ext\ and in windows\system32\.

    Any thoughts what the underlying issues might be?

    TIA,
    David

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP - MySQL interface problems

    Your problem is that neither MySQL nor MySQLi are installed properly.

    What server are you running and how did you do the install?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    I'm running Apache v.2.2.3 which I installed per the instructions in the book I'm studying. Basically, I just installed apache_2.2.3-win32-x86-no_ssl.msi into C:\apache. The network domain and Service name were both set to 'localhost'.

    FWIW, the server serves up pages just fine from what I can tell.

  4. #4
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    Re-reading your post, I realize you may be asking about the DB server, not the web server. I'm running MySQL v.5.0 which appears to work from the command line interface, ie.., I can execute SELECTs, etc.

    I installed mysql-essential-5.0.26-win32.msi. What about the installation would you want to know?


    Thanks for your help,
    David

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP - MySQL interface problems

    I was just thinking along the lines of your PHPMyAdmin configuration. Are you sure that you used the setup script properly?

    Concerning your code, there are no errors. Since you are getting an error in regards to MySQLi, then something with that extension is not correct.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    Right, any idea what it might be? Any suggestions re where/how should it be configured such that I might check to confirm that it's properly handled?

    Thanks again,
    David

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP - MySQL interface problems

    Well, when you first copy the PHPMyAdmin folder to your webserver, you should get an error asking you to configure. Did you do this? After configuring it, you have to download the config.inc.php file, make it read only, and place it in the PHPMyAdmin root folder. Did you do these steps also?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    hmmm, interesting. I just copied the phpMyAdmin folder to c:\apache\htdocs via Windows Explorer so, as far as it knew, I was just moving files. Was this not the appropriate technique? If so, how would it know to ask me to configure?

    RE: config.inc.php, I wrote my own as follows in the phpMyAdmin root:
    <?php
    $cfg['PmaAbsoluteUri'] = "http://localhost/phpMyAdmin/";
    $cfg['Servers'][1]['host'] = "localhost";
    $cfg['Servers'][1]['auth_type'] = "config";
    $cfg['Servers'][1]['user'] = "root";
    $cfg['Servers'][1]['pawword'] = "password";
    ?>

    FYI, I changed the file attribute to read-only with no change in the results.

    Thanks,
    David

  9. #9
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    Following a documentation link on the resulting error page, I come to the following:

    "To connect to a MySQL server, PHP needs a set of MySQL functions called "MySQL extension". This extension may be part of the PHP distribution (compiled-in), otherwise it needs to be loaded dynamically. Its name is probably mysql.so or php_mysql.dll. phpMyAdmin tried to load the extension but failed.

    Usually, the problem is solved by installing a software package called "PHP-MySQL" or something similar."

    Given what I've described my configuration to be re php_mysqli.dll above, what else should I do?

    David

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP - MySQL interface problems

    I assume you have downloaded and installed the latest PHPMyAdmin. That would be version 2.9. If you run the setup script, you can use the MySQLi extension instead of the MySQL one.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  11. #11
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    Thanks for hanging in there with me. I've checked out the setup facility as you said but I really don't know what I need to do. I have selected mysqli as the php extension to use but beyond that, I'm not sure what to do.

    Here are a couple of snapshots of the setup utility:

    1. Initial screen: http://www.drschwartz.net/personal/t...in_setup_1.jpg
    2. Configuration overview: http://www.drschwartz.net/personal/t...in_setup_2.jpg

    Any additional help would be greatly appreciated!

    FYI, I discovered that the extension_dir in php.ini was not pointing to the php/ext directory which is holding the dlls. I fixed that but still have the same problem.

    Thanks,
    David

  12. #12
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP - MySQL interface problems

    Okay. Here is a walkthrough on how to setup the phpMyAdmin configuration.

    1. If exists, delete the current config.inc.php.
    2. Run the setup script.
    - Server Hostname: server IP
    - phpMyAdmin control user: root
    - phpMyAdmin control user password: root password
    3. Click "Update"
    4. Now click "Download" and save this file to where the phpMyAdmin folder.
    5. Make it read-only.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  13. #13
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    Thanks. I did as you instructed with the same results. Here's the resulting config.inc.php:

    <?php
    /*
    * Generated configuration file
    * Generated by: phpMyAdmin 2.9.0.2 setup script by Michal Čihař <michal@cihar.com>
    * Version: $Id: setup.php,v 1.36.2.3.2.1 2006/10/03 13:11:08 nijel Exp $
    * Date: Mon, 23 Oct 2006 22:54:35 GMT
    */

    /* Servers configuration */
    $i = 0;

    /* Server localhost (config:root) [1] */
    $i++;
    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['connect_type'] = 'tcp';
    $cfg['Servers'][$i]['compress'] = false;
    $cfg['Servers'][$i]['controluser'] = 'root';
    $cfg['Servers'][$i]['controlpass'] = 'password';
    $cfg['Servers'][$i]['auth_type'] = 'config';
    $cfg['Servers'][$i]['user'] = 'root';

    /* End of servers configuration */

    ?>

  14. #14
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP - MySQL interface problems

    Is your server Windows based? If so, try installing EasyPHP and test that. If that works, you know the installation is bad.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  15. #15
    Join Date
    Oct 2006
    Location
    Seattle, WA, USA
    Posts
    11

    Re: PHP - MySQL interface problems

    Yes, it's windows xp. I've installed EasyPHP 1.8 and I can access phpMyAdmin. What does that tell us?

    David

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured