Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2010
    Posts
    3

    Unanswered: prob:connection to database

    hey everyone!!!!
    well i have got a problem with connecting to a mysql database using php. I used this package "mysql-noinstall-5.1.44-win32.zip" and extracted it to c:\mysql and added c:\mysql\bin to the PATH variable and used the following command in command prompt to start mysql:
    c:\mysql\bin\mysqld --standalone
    well mysql did start and everything went well accessing mysql in command prompt. Well under the database "mysql" in the table "user" i created a new user "php" with a password="****" and hostname = "localhost" but when i try to access this database with a following php routine:

    //test.php
    <?php
    $username = "php";
    $password = "****";
    $hostname = "localhost";
    echo $hostname;
    $connection = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
    echo "Connected to MySQL";
    ?>

    and when i accesses it with my browser using localtost/test.php, all i get is "localhost" displayed on screen, "Connected to mysql" never gets displayed not i get any error..
    note: i am using windows 7(32-bit-ultimate)and mysql 5.1.44.
    any help will be appreciated....thxxx

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    try echoing the MySQL error message in your or die statement
    PHP Code:
    or die ("MySQL crapped out whinging:".mysql_error()." error code:".mysql_error); 
    also you need to make certain your script/installation is displayign errors
    PHP Code:
    ini_set('display_errors','On')
    error_reporting(E_ALL); 
    or
    PHP Code:
    error_reporting(-1); 
    its almost certainly going to be a problem with the permissions that were GRANTed to that user. check da manual for the correct GRANT syntax.
    you may find it easier to GRANT permissions using MySQL Administrator availabel fromt eh MySQL website as part of the MySQL GUI tools.#

    the PHP manual is usually a pretty good source for such issues
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Feb 2010
    Posts
    3
    ok now i set display_error "ON" in php.ini file and now its displaying this error for my mysql_connect() command:

    Fatal error: Call to undefined function mysql_connect() in C:\webroot\test.php on line 7
    any ideas??
    Last edited by aimseeker; 03-01-10 at 10:41.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    thast woudl suggest the php / Mysql installation is damaged or not installed
    try running the php function phpinfo() in a script
    PHP Code:
    <?php
     
    echo 'PHP is working.<br>';
     echo 
    phpinfo();
    ?>
    examine the results it should tell you what database connections are installed.

    my suspiscion is that you will either need to repair to reinstall PHP and possibly the webserver. if you have to do that either get someone who is experienced in doing it or consider downloading the XAMPP relevant to your OS


    as this is a PHP problem not a MySQL problem you may be better off asking PHP related questions there
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Feb 2010
    Posts
    3

    Problem solved!!!

    ok this post solved my problem:
    1.Search your server for libmysql.dll. Delete any instance of libmysql.dll that is not in the C:\PHP directory. This limits the possibility of older MySQL client API's being used with PHP.

    2.Search your server for php_mysql.dll. Delete any instance of php_mysql.dll that is not in the C:\PHP directory. This limits the possibility of older MySQL client API's being used with PHP.

    3.Open your C:\%WIN%\php.ini file in a text editor (Notepad will work).

    Search for the line that looks like --> ;extension=php_mysql.dll

    Change this line to --> extension=php_mysql.dll

    Uncomment: extension_dir="c:\php\ext"

    Save the modified php.ini file.

    4. Copy php.ini to C:\%WIN%\System32

    5. Copy C:\PHP\libmysql.dll and C:\PHP\ext\php_mysql.dll to the C:\%WIN%\system32 folder.
    thxx everyone

Posting Permissions

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