Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要添加表前缀(文件MySQL.PHP)_Php_Mysql_Database - Fatal编程技术网

需要添加表前缀(文件MySQL.PHP)

需要添加表前缀(文件MySQL.PHP),php,mysql,database,Php,Mysql,Database,我需要为使用此代码创建的表添加前缀。我需要做什么?我尝试重命名函数,但它不起作用。我还需要在另一个文件中添加表前缀,与此类似。不需要重新编写整个代码就可以了吗?我是个新手 <? class DB_Sql { var $Host = "localhost"; // Hostname of our MySQL server. var $Database = "my_database"; // Logical database name on that server. var $User

我需要为使用此代码创建的表添加前缀。我需要做什么?我尝试重命名函数,但它不起作用。我还需要在另一个文件中添加表前缀,与此类似。不需要重新编写整个代码就可以了吗?我是个新手

<?
class DB_Sql {
var $Host     = "localhost"; // Hostname of our MySQL server.
var $Database = "my_database"; // Logical database name on that server.
var $User     = "user"; // User und Password for login.
var $Password = "";

var $Link_ID  = 0;  // Result of mysql_connect().
var $Query_ID = 0;  // Result of most recent mysql_query().
var $Record   = array();  // current mysql_fetch_array()-result.
var $Row;           // current row number.

var $Errno    = 0;  // error state of query...
var $Error    = "";
var $num_queries = 0;


function halt($msg) {
    printf("</td></tr></table><b>Database error:</b> %s<br />\n", $msg);
    printf("<b>MySQL Error</b>: %s (%s)<br />\n",
    $this->Errno,
    $this->Error);
    die("Session halted.");
}

function connect($thehost, $thedb, $theuser, $thepwd) {
    $this->Host=$thehost;
    $this->Database=$thedb;
    $this->User=$theuser;
    $this->Password=$thepwd;

    if ( 0 == $this->Link_ID ) {
        $this->Link_ID=mysql_connect($this->Host, $this->User, $this->Password);
        if (!$this->Link_ID) {
            $this->halt("Link-ID == false, connect failed");
            return false;
        }
        if (!mysql_query(sprintf("use %s",$this->Database),$this->Link_ID)) {
            $this->halt("cannot use database ".$this->Database);
            return false;
        }
        return true;
    }
    return false;
}

function free_result($query_id=-1) {
    if ($query_id!=-1) {
        $this->query_id=$query_id;
    }
}


function fetch_array($query_id=-1,$query_string="") {
    if ($query_id!=-1) {
        $this->query_id=$query_id;
    }
    if ( isset($this->query_id) ) {
        $this->record = mysql_fetch_array($this->query_id);
    } else {
        if ( !empty($query_string) ) {
            $this->halt("Invalid query id (".$this->query_id.") on this query: $query_string");
        } else {
            $this->halt("Invalid query id ".$this->query_id." specified");
        }
    }
    return $this->record;
}


function query($Query_String) {
    //  $this->connect();
    $this->num_queries++;
    #printf("<br /><font color=red><b>Debug: query = %s</b></font><br />", $Query_String); // Use for debugging
    $this->Query_ID = mysql_query($Query_String,$this->Link_ID);
    $this->Row   = 0;
    $this->Errno = mysql_errno();
    $this->Error = mysql_error();
    if (!$this->Query_ID) {
        $this->halt("Invalid SQL: ".$Query_String);
    }
    return $this->Query_ID;
}


function next_record() {
    $this->Record = mysql_fetch_array($this->Query_ID);
    $this->Row   += 1;
    $this->Errno = mysql_errno();
    $this->Error = mysql_error();
    $stat = is_array($this->Record);
    if (!$stat) {
        mysql_free_result($this->Query_ID);
        $this->Query_ID = 0;
    }
    return $stat;
}


function seek($pos) {
    $status = mysql_data_seek($this->Query_ID, $pos);
    if ($status)
    $this->Row = $pos;
    return;
}


function num_rows() {
    return mysql_num_rows($this->Query_ID);
}

function num_fields() {
    return mysql_num_fields($this->Query_ID);
}


function f($Name) {
    return $this->Record[$Name];
}

function p($Name) {
    print $this->Record[$Name];
}

function affected_rows() {
    return @mysql_affected_rows($this->Link_ID);
}



function get_temps() {
    while ($row = mysql_fetch_array($this->Query_ID)) {
        $templ[$row["id"]] = $row['con'];
    }
    echo "$templ[1]<br />$templ[2]";
}

function get_temp() {
    return mysql_fetch_array($this->Query_ID);
}

function query_first($query_string) {
    // does a query and returns first row
    $query_id = $this->query($query_string);
    $returnarray=$this->fetch_array($query_id, $query_string);
    $this->free_result($query_id);
    return $returnarray;
}


function get_tables() {
    $tables = mysql_list_tables($this->Database);

    while ($row = mysql_fetch_row($tables)) {
        $return[] = "$row[0]";
    }
    return $return;
}

function querySingle($query, $value) {
    return arrayValue($this->fetch_array($this->query($query)),$value);
}


function get_fields($table) {
    $result = mysql_query("SHOW COLUMNS FROM $table");
    if (!$result) {
        $this->halt("Invalid SQL: Could not run query: " . mysql_error());
    }
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            $return[] = $row['Field']."^".
            iif($row['Type'],$row['Type']." ")." ".
            iif($row['Null']==0,"NOT NULL ","NULL ")." ".
            //                  iif($row['Key'],$row['Key']." ")." ".
            "default '".$row['Default']."' ".
            iif($row['Extra'],$row['Extra']." ")."".

            iif(($row['Key'] == "PRI"), "*PRIMARY KEY (`".$row['Field']."`)").
            iif(($row['Key'] == "MUL"), "*KEY (`".$row['Field']."`)")
            ;
        }
    }
    return $return;
}


function sql_close()
{
    if($this->db_connect_id)
    {
        if($this->query_result)
        {
            @mysql_free_result($this->query_result);
        }
        $result = @mysql_close($this->db_connect_id);
        return $result;
    }
    else
    {
        return false;
    }
}



}






?>
1。不要使用mysql。当您的主机移动到PHP7时,所有mysql_uu函数将不再可用。使用PDO系统或mysqli(其语法与mysql稍有不同)
2.变量
一个变量的关键在于它的变化。现在我快速通读了您的代码,老实说,我没有看到设置表名的地方

例子 上面加载了您的类(为了空间和可读性而省略)


如果这不能回答您的问题,您需要更新您的问题,并提供更多信息,说明哪些问题没有按预期工作。您希望看到的内容与您实际看到的内容相比。

vode只创建html表,而不创建其他内容。你说的是什么前缀?请不要使用,它已经被弃用了(在PHP7中永远消失了),特别是如果你只是在学习PHP,那么就把精力花在学习
PDO
数据库扩展上。
$db = new DB_Sql();
$db->connect('localhost','user','pw','database');
$result = $db->query("SELECT * FROM ".$table_prefix."users");//Or whatever your query is.
//Do what you need with the stuff.
$db->free_result($result);
$db->sql_close();