Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2011
    Posts
    3

    Unanswered: convert mysql code to mysqli

    hi

    i have a script that works perfectly, but i want to change to mysqli

    so, the mysql is
    PHP Code:
    <?php

    include("includes/banco.php");
    $theclass->conecta();


    $consulta"design";  

    $rs mysql_query('select profissao  from empregos where profissao like "'.$consulta .'%"');

    $data = array();
    if ( 
    $rs && mysql_num_rows($rs) )
    {
        while( 
    $row mysql_fetch_array($rsMYSQL_ASSOC) )
        {
            
    $data[] = array(
                
    'label' => $row['profissao']  
            );
        }
    }

    echo 
    json_encode($data);
    flush();


    ?>
    and the result is:
    Code:
    [{"label":"Design"},{"label":"Design Gráfico"},{"label":"Design"},{"label":"Design"}]
    the mysqli at the moment is

    PHP Code:
    <?php

    include ('includes/includesMy.php');


    $consulta"design";


    (
    $sql $db->prepare('select profissao from empregos where profissao like ?'));

    $sql->bind_param('s'$consulta);
    $sql->execute();
    $sql->bind_result($profissao);

    $data = array();

    while (
    $sql->fetch()) {
        
    $data[] = array(
                
    'label' => $row['profissao']  
        );

    }
        echo 
    json_encode($data);
    $sql -> close();
    $db -> close();


    ?>
    ant the result is
    Code:
    [{"label":null},{"label":null},{"label":null}]

    the mysqli is not working correctly, the number of outputs are different and label are null (only matches the specific word design and not design gráfico )

    any help?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    where do you think $row is being set?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Apr 2011
    Posts
    3
    solved, i can't use $row in mysqli

Posting Permissions

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