mysqli help needed
Posted: Wed Dec 01, 2010 1:23 pm
Hi I have developed my website using general mysql function now i want to change it to mysqli so plz help me with this. here is my code.
function data($dbuser,$dbpassword,$database,$host)
{
$this->insert_details = array();
$this->connection = mysql_connect($host, $dbuser, $dbpassword) or die(mysql_error());
mysql_select_db($database, $this->connection);
}
function exec($sql)
{
if(!$this->connection){
echo "error";
}
$result = mysql_query($sql,$this->connection) or die(mysql_error());
if($result)
{
return $result;
}
else
{
//print_r($sql."<br>");
print_r(mysql_error());
die;
}
}
function fetch_array($result)
{
return mysql_fetch_array($result);
}
function count_row($result)
{
return mysql_num_rows($result);
}
function insert_id()
{
return mysql_insert_id();
}
function closeconnection()
{
$this->connection_aborted();
}
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
public function SelectData(){
$QueryString = "";
$result = null;
if($this->select_columns!=""){
$QueryString = "SELECT ".$this->select_columns." FROM ".$this->table_name;
if($this->where_clause!=""){
$QueryString .= " WHERE ".$this->where_clause;
}
if($this->group_by!=""){
$QueryString .= " GROUP BY ".$this->group_by;
}
if($this->order_by!=""){
$QueryString.= " ORDER BY ".$this->order_by;
}
if($this->limit_by!=""){
$QueryString.=" LIMIT ".$this->limit_by;
}
$result = $this->exec($QueryString);
}
return $result;
}
public function InsertData(){
$ret_id = 0;
$cols = array();
$vals = array();
if($this->table_name!="" && count($this->insert_details)>0){
$QueryString = "INSERT INTO ".$this->table_name;
foreach($this->insert_details as $columns=>$values){
$cols[] = $columns;
$vals[] = "'".$values."'";
}
$colString = implode(",",$cols);
$valStirng = implode(",",$vals);
$QueryString = $QueryString."(".$colString.")VALUES(".$valStirng.")";
// echo "<br />".$QueryString;
$result = $this->exec($QueryString);
if($result){
$ret_id = $this->insert_id();
}
}
$this->insert_details = array();
return $ret_id;
}
public function UpdateData(){
$ret_id = 0;
$cols = array();
$vals = array();
if($this->table_name!="" && count($this->insert_details)>0){
$QueryString = "UPDATE ".$this->table_name." SET ";
foreach($this->insert_details as $columns=>$values){
$QueryString = $QueryString.$columns."='".$values."',";
}
$ret_id = $this->affected_rows();
echo $QueryString;
}
return $ret_id;
many thanks in advance..
mg
function data($dbuser,$dbpassword,$database,$host)
{
$this->insert_details = array();
$this->connection = mysql_connect($host, $dbuser, $dbpassword) or die(mysql_error());
mysql_select_db($database, $this->connection);
}
function exec($sql)
{
if(!$this->connection){
echo "error";
}
$result = mysql_query($sql,$this->connection) or die(mysql_error());
if($result)
{
return $result;
}
else
{
//print_r($sql."<br>");
print_r(mysql_error());
die;
}
}
function fetch_array($result)
{
return mysql_fetch_array($result);
}
function count_row($result)
{
return mysql_num_rows($result);
}
function insert_id()
{
return mysql_insert_id();
}
function closeconnection()
{
$this->connection_aborted();
}
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
public function SelectData(){
$QueryString = "";
$result = null;
if($this->select_columns!=""){
$QueryString = "SELECT ".$this->select_columns." FROM ".$this->table_name;
if($this->where_clause!=""){
$QueryString .= " WHERE ".$this->where_clause;
}
if($this->group_by!=""){
$QueryString .= " GROUP BY ".$this->group_by;
}
if($this->order_by!=""){
$QueryString.= " ORDER BY ".$this->order_by;
}
if($this->limit_by!=""){
$QueryString.=" LIMIT ".$this->limit_by;
}
$result = $this->exec($QueryString);
}
return $result;
}
public function InsertData(){
$ret_id = 0;
$cols = array();
$vals = array();
if($this->table_name!="" && count($this->insert_details)>0){
$QueryString = "INSERT INTO ".$this->table_name;
foreach($this->insert_details as $columns=>$values){
$cols[] = $columns;
$vals[] = "'".$values."'";
}
$colString = implode(",",$cols);
$valStirng = implode(",",$vals);
$QueryString = $QueryString."(".$colString.")VALUES(".$valStirng.")";
// echo "<br />".$QueryString;
$result = $this->exec($QueryString);
if($result){
$ret_id = $this->insert_id();
}
}
$this->insert_details = array();
return $ret_id;
}
public function UpdateData(){
$ret_id = 0;
$cols = array();
$vals = array();
if($this->table_name!="" && count($this->insert_details)>0){
$QueryString = "UPDATE ".$this->table_name." SET ";
foreach($this->insert_details as $columns=>$values){
$QueryString = $QueryString.$columns."='".$values."',";
}
$ret_id = $this->affected_rows();
echo $QueryString;
}
return $ret_id;
many thanks in advance..
mg