If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > convert mysql code to mysqli

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-11, 20:12
felito felito is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
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?
Reply With Quote
  #2 (permalink)  
Old 04-14-11, 02:21
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
where do you think $row is being set?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 04-14-11, 09:33
felito felito is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
solved, i can't use $row in mysqli
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On