그래서 백업 클래스를 만들려고하고 있는데, 지금까지 제가 가지고있는 것입니다. 문제는 $ tbl_data가 비어 있습니다. 내가 도대체 뭘 잘못하고있는 겁니까.PHP5 Mysqli 클래스가 데이터를 출력하지 않습니다.
데이터베이스에 성공적으로 연결되었습니다.
'echo $ tbl_data'가 없으면 '$ current_table - 현재 테이블'출력이 올바르지 만 'echo $ tbl_data'가 사용되면 첫 번째 테이블 만 표시됩니다 (두 개의 테이블을 백업하려고합니다).
class mBackup{
private $_connection = ""; //db connection var
private $output = ""; //sql output
private $tbl_data = "";
private $tbl_row = "";
private $nfields = "";
private $create_table_query = "";
private $create_table_output = "";
public function __construct($dbhost,$dbname,$dbuser,$dbpassword){
$this->_connection = new mysqli($dbhost,$dbuser,$dbpassword,$dbname);
//possible connection error
if($this->_connection->connect_errno){
echo "Failed to connect to the DB";
}
else{
echo "Connected<br />";
}
}
public function backup_db(){
//get the table names from the DB and store in an array
$result = $this->_connection->query("SHOW TABLES");
//get the TABLE names
while($row = $result->fetch_row())
{
$table_names[] = $row[0];
}
//For each table
foreach($table_names as $current_table)
{
echo $current_table." - current table<br />"; //debug
$tbl_data = "";
$tbl_row = "";
$nfields = "";
$create_table_query = "";
$create_table_output = "";
//SELECT Everything from the table in use
$query = $this->_connection->prepare("SELECT * FROM ?");
$query->bind_param('s', $current_table);
$query->execute();
$query->bind_result($tbl_data);
$query->fetch();
echo $tbl_data."<br/>";
}
}
"연결됨"이상입니까? –
Yep과 $ current_table - 현재 테이블 출력. – mintuz