目前我在functions.php
constants.php
包含数据库名称,用户密码等。
我想将此课程用作 mysqli 。
网上有很多课程示例。但我无法做到......
如果我可以将其转换为mysqli,我可以节省很多时间在其他所有页面上更改班级名称等。
我在 functions.php
文件中提供示例代码。如何将其转换为mysqli?
我已经尝试Mysqli Converter但它对我帮助不大......
<?
ob_start();
include_once("constants.php");
//create class
Class bsq
{
function connect_db()
{
mysql_connect(HST,USR,PWD) or die(mysql_error()); //die("Failed to Connecting MYSQL");
mysql_select_db(DBN) or die(mysql_error()); //die("Failed to connect database");
}
function webdreamselect($table,$where,$start,$end,$orderby,$orderbyvalue)
{
$sql="select * from ".$table."";
if($where!="") {
$sql.=" where ".$where."";
}
if($orderby!="" && $orderbyvalue!="" ) {
$sql.=" order by ".$orderby." ".$orderbyvalue."";
}
if($end > 0 ) {
$sql.=" limit ".$start.",".$end." ";
}
//echo $sql;
$seldata=@mysql_query($sql);
return $seldata;
}
function webdreamupdate($tbl, $sf, $sv, $wf, $wv, $prn)
{
$query.=" UPDATE ".$tbl." SET " ;
/* Here updating fields and values are composed */
if(is_array($sf))
{
if(sizeof($sf) > 0)
{
for($j=0; $j<sizeof($sf); $j++)
{
$update_vars.= " $sf[$j] = '$sv[$j]' ";
if($j<sizeof($sf)-1)
$update_vars .= ", ";
}
}
}
else
{
$update_vars.= " $sf = '$sv' ";
}
$query.= $update_vars;
/*Here condition is created*/
if(is_array($wf))
{
if(sizeof($wf) > 0)
{
for($k=0; $k<sizeof($wf); $k++)
{
$condition.= " $wf[$k] = '$wv[$k]' ";
if($k<sizeof($wf)-1)
$condition .= " and ";
}
}
}
else
{
if($wf)
$condition = $wf." = '$wv' ";
else
$condition="1";
}
$query.= " WHERE $condition ";
if($prn==1)
{
//echo $query;
}
//echo $query;
$result = @mysql_query($query) or die(mysql_error());
return $result;
}
答案 0 :(得分:1)
如何将其转换为mysqli?
直截了当地回答:
答案 1 :(得分:-1)
像这样使用你的functions.php(所有mysql_都替换为mysqli _)
<?
ob_start();
include_once("constants.php");
//create class
Class bsq
{
function connect_db()
{
mysqli_connect(HST,USR,PWD) or die(mysqli_error()); //die("Failed to Connecting MYSQL");
mysqli_select_db(DBN) or die(mysqli_error()); //die("Failed to connect database");
}
function webdreamselect($table,$where,$start,$end,$orderby,$orderbyvalue)
{
$sql="select * from ".$table."";
if($where!="") {
$sql.=" where ".$where."";
}
if($orderby!="" && $orderbyvalue!="" ) {
$sql.=" order by ".$orderby." ".$orderbyvalue."";
}
if($end > 0 ) {
$sql.=" limit ".$start.",".$end." ";
}
//echo $sql;
$seldata=@mysqli_query($sql);
return $seldata;
}
function webdreamupdate($tbl, $sf, $sv, $wf, $wv, $prn)
{
$query.=" UPDATE ".$tbl." SET " ;
/* Here updating fields and values are composed */
if(is_array($sf))
{
if(sizeof($sf) > 0)
{
for($j=0; $j<sizeof($sf); $j++)
{
$update_vars.= " $sf[$j] = '$sv[$j]' ";
if($j<sizeof($sf)-1)
$update_vars .= ", ";
}
}
}
else
{
$update_vars.= " $sf = '$sv' ";
}
$query.= $update_vars;
/*Here condition is created*/
if(is_array($wf))
{
if(sizeof($wf) > 0)
{
for($k=0; $k<sizeof($wf); $k++)
{
$condition.= " $wf[$k] = '$wv[$k]' ";
if($k<sizeof($wf)-1)
$condition .= " and ";
}
}
}
else
{
if($wf)
$condition = $wf." = '$wv' ";
else
$condition="1";
}
$query.= " WHERE $condition ";
if($prn==1)
{
//echo $query;
}
//echo $query;
$result = @mysqli_query($query) or die(mysqli_error());
return $result;
}