Page 1 of 1

mysqli extension help

Posted: Mon Oct 24, 2005 10:34 am
by eremini
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.

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;
	      
	  }
Thank you very much! Glad to be at this great forums and sorry for the english :)

Posted: Tue Oct 25, 2005 3:18 pm
by RobertGonzalez
Try looking at the mysqli_stmt_prepare function. There are a few examples of what to do and how to do it.