mysqli help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mgnep
Forum Newbie
Posts: 1
Joined: Wed Dec 01, 2010 1:09 pm

mysqli help needed

Post by mgnep »

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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: mysqli help needed

Post by pickle »

1) Wrap your code in tags
2) Don't just ask us to do your work. Try it yourself & if you have a specific problem post the relevant code explaining what specifically you're trying to do and what you've tried yourself.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply