Need help with mysqli_ functions

Discussion in 'PHP' started by phantom, Mar 11, 2011.

  1. #1
    I am trying to switch my scripts over to use mysqli functions but am having a heck of a time here is my code so far.

    $link = mysqli_connect("localhost", "bartsimpson", "spartaa", "spankdb");
    
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    $q = "select *  from projects where pid='14' order by pid limit 1 ";
    $result = mysqli_multi_query($link, $q);
     while(   $row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
    $tz = $row['tz'];
    
    echo $tz;
    
    }
    
    Code (markup):
    Can anyone tell me what I am doing wrong here?
     
    phantom, Mar 11, 2011 IP
  2. eleetgeek

    eleetgeek Peon

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    My friend, I understand your pain. Been through it. But, honestly, mysqli is not as easy as mysql_connect.

    I learnt from :
    http://uk2.php.net/manual/en/book.mysqli.php

    Go through the manual and also look at sample codes.

    Learn it the hard way :)
     
    eleetgeek, Mar 14, 2011 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    I think if you are going to switch, you should access your data as an object and not procedural.

    
    
    $link = mysqli_connect("localhost", "bartsimpson", "spartaa", "spankdb");
    
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    $q = "select *  from projects where pid='14' order by pid limit 1 ";
    
    $result = $link->query($q);
    
    while($row = $result->fetch_assoc()){
        echo $row['tz'];
    }
    
    
    PHP:
     
    jestep, Mar 15, 2011 IP