SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jan 2014
    0 Post(s)
    0 Thread(s)

    PHP/MySQL Connection Nightmare

    On my ISP's server is installed:

    MySQL 5.5.12
    PHP 5.2.17

    Via phpMyAdmin I setup a simple test database. Now I want to do a test access of the data using a PHP script.

    My ISP said the server path to my test database (john_test) is: /var/lib/mysql/

    And that my access to my test database 'john_test' would be: /var/lib/mysql/john_test

    It appears I'm not doing something right, because I cannot connect with the following script:

    PHP Code:

    //connect to server 

    $connect mysql_connect("/var/lib/mysql/john_test""john""my_real_password_goes_here");
    if (!
    $connect) {
    'Not connected : ' mysql_error());

    //connect to datatbase

    $db_selected mysql_select_db("john_test"$connect);
    if (!
    $db_selected) {
        die (
    'Can\'t use john_test : ' mysql_error());

    //query the database

    $query mysql_query("SELECT * FROM table1 WHERE firstname = 'John' ");

    //fetch the results / convert results into an array

    WHILE($rows mysql_fetch_array($query)):

    $firstname $rows['firstname'];
    $lastname $rows ['lastname'];



    I'm also a bit suspicious of not using { } 's with the WHILE loop instead of just the ":" as seen in some other code.

    Any assistance would be appreciated !

    Thanks very much.

    Last edited by SpacePhoenix; Jan 30, 2014 at 13:59. Reason: placed php tags around php code


Posting Permissions

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