Problem setting up PHP with mySQL, computer isn't even nice enough to give error

Discussion in 'PHP' started by GSto, May 12, 2008.

  1. #1
    I am trying to set up a developer server on my Computer, using Apache, PHP, and mySQL. I followed all the instructions, and everything seems to be working fine, then I tried to write a simple PHP script to see if I could connect to the mySQL server. It won't echo the error messages or do anything, except echo the first line! I can't understand why it is stopping completely, and not giving any error messages. here is the script:

    
    <?php
    $host = "localhost";
    $user = "*********";
    $password = "**********";
    $dbname = "test";
    echo'hello world';
    
    $cxn = mysqli_connect($host,$user,$password,$dbname)
    		or die("could not connect");
    
    	
    $query = "SELECT * FROM friends";
    $result = mysqli_query($cxn, $query)
    		    or die("query failed");
    
    echo '$result';
    echo 'goodbye, world!';	
    ?>
    
    PHP:
    all this says is "hello, world!" what is going on here? how can I fix this?
     
    GSto, May 12, 2008 IP
  2. chtdatweb

    chtdatweb Well-Known Member

    Messages:
    1,473
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Have you got any data in the table "friends" why are you expecting there to be an error? If your seeing Hello world one has to assume that you are also seeing "goodbye, world!" - or is this not being displayed either?
     
    chtdatweb, May 12, 2008 IP
  3. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    MAKE SURE YOU ARE CONNECTING TO THE DATA BASE BY USING THIS

    
    <?php
    $host = "localhost";
    $user = "*********";
    $password = "**********";
    $dbname = "test";
    
    $link = mysqli_connect($host,$user,$password,$dbname);
    
    /* check connection */
    if (!$link) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    printf("Host information: %s\n", mysqli_get_host_info($link));
    
    /* close connection */
    mysqli_close($link);
    ?>
    
    
    PHP:
     
    cornetofreak, May 12, 2008 IP
  4. GSto

    GSto Peon

    Messages:
    218
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    mysqli. it's PHP 5, mySQL 5, and Apache 2.2 . sorry, guess I should have put that in my first post.
     
    GSto, May 12, 2008 IP
  5. GSto

    GSto Peon

    Messages:
    218
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    'goodbye, world' was not being displayed. I used the mySQL client to create the database and table, so I know it is there. I just tried running the other script posted, and nothing showed up. Any idea what could be causing this?
     
    GSto, May 12, 2008 IP
  6. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    so if nothing happend try using mysql not mysqli due to the fact the same one you posted it was working no problem must be your apache i sugggest xampp :)
     
    cornetofreak, May 12, 2008 IP
  7. WhaLberg

    WhaLberg Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Use "error_reporting(E_ALL);" and mysql_error(); to see what's the error in PHP and / or MySQL.
     
    WhaLberg, May 14, 2008 IP
  8. scriptaty

    scriptaty Banned

    Messages:
    522
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    first of all use xampp or wamp in localhost then installing php and mysql.

    And hello world will surely be displayed in the result as you have already asked for that

    second thing is that you need to have data in database and last thing is that in PHP5 you won't get error automatically..I forgot the right code to get error in php5 as I am not master of php but still learning and doing nice.

    bu i think it's errchk() or something like that , which you need to insert in php5 to get error displayed.I will update you tomorrow after I get it.
     
    scriptaty, May 14, 2008 IP