目前我在functions.php
中有以下mysql的类、函数结构
constants.php
包含数据库名称、用户密码等
我想将此类用作mysqli。
网上有很多类(class)示例。但我没能做到......
如果我可以将其转换为 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;
}
最佳答案
How can I convert it to mysqli ?
开门见山的回答:
- 打开manual page for mysqli并通读一遍。
- 创建一个测试脚本并练习运行各种查询一段时间,以熟悉 mysqli。
- 打开您最喜欢的代码编辑器,加载此文件并设置为重写。
- 完成后,尝试测试它。
- 如果您在此过程中遇到一些特定错误,欢迎您通过 Google 进行搜索,如果没有成功,请在 Stack Overflow 上提问。
关于php - mysql 到 mysqli 类函数转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38322801/