【发布时间】:2018-02-25 04:51:07
【问题描述】:
以前的程序员使用了一个名为数据库的类,它具有连接字符串和一堆函数。我现在必须将其转换为 MySQLi,我不知所措。
class database {
var $sql='';
var $result='';
function database( $host='localhost', $user, $pass, $db) {
// perform a number of fatality checks, then die gracefully
if (!function_exists( 'mysql_connect' )) {
//or die( 'FATAL ERROR: MySQL support not available. Please check your configuration.' );
exit();
}
bla..bla..bla - bunch of code goes here
function get_events_by_user($username) {
$sql = "SELECT event_id FROM user_events WHERE username = '$username'";
$result = mysql_query($sql);
return $result;
}
}
我试过了
var $link=mysqli_connect('localhost', $user, $pass);
用作
$result = mysqli_query($link,$sql);
但我不能使用表达式作为变量值,我不知道还能做什么。
非常感谢! :)
【问题讨论】:
-
从手册php.net/manual/en/book.mysqli.php 开始,记住将连接作为参数传递给您的方法。否则,您将遇到超出范围的问题。
-
如何将连接作为参数传递给我的方法?