mysqli extension help
Posted: Mon Oct 24, 2005 10:34 am
Hello,
I maintain a php/mysql based webpage, but I only started with php little while ago. The original code was using the old mysql extension, now I rewrote it to use mysqli, but my next step is prepared statements. I am having some trouble with this
I have multiple pages, but mysql functions are stored in one file, like
function update_sql($table, $fields, $option = '')
function delete_sql($table, $option = '')
etc...
I just don't understand the prepared syntax and I can't find a lot of examples
I would really really appreciate if someone can for example convert this to mysqli prepared, I think I'll get the rest. I learn best on examples.
Thank you very much! Glad to be at this great forums and sorry for the english 
I maintain a php/mysql based webpage, but I only started with php little while ago. The original code was using the old mysql extension, now I rewrote it to use mysqli, but my next step is prepared statements. I am having some trouble with this
I have multiple pages, but mysql functions are stored in one file, like
function update_sql($table, $fields, $option = '')
function delete_sql($table, $option = '')
etc...
I just don't understand the prepared syntax and I can't find a lot of examples
I would really really appreciate if someone can for example convert this to mysqli prepared, I think I'll get the rest. I learn best on examples.
Code: Select all
function get_sql($table, $fields = '*', $option = '', $order = '', $limit = '')
{
global $DBc;
global $stats;
$stats['query']++;
$query = "SELECT ".$fields." FROM ".$table;
if($option != '') { $query .= " WHERE ".$option; }
if($order != '') { $query .= " ORDER by ".$order; }
if($limit != '') { $query .= " LIMIT ".$limit; }
$query_result=mysqli_query($DBc,$query) or die(mysqli_error());
$k = 0;
while($tmp = mysqli_fetch_array($query_result))
{
//$row = mysqli_fetch_row($query_result);
//$data[$k] [mysqli_field_name($query_result,$k2)] = $row[$k2];
$data[$k] = $tmp;
$k++;
}
mysqli_free_result($query_result);
return $data;
}