2016-02-27 146 views
-1

如何在數據庫中選擇tbl_uploads表?數據庫選擇(PHP)

phpMyAdmin的IMG

enter image description here

<?php 
 
$dbhost = ""; 
 
$dbuser = ""; 
 
$dbpass = ""; 
 
$dbname = ""; 
 
    
 
mysql_connect($dbhost,$dbuser,$dbpass) or die('cannot connect to the server'); 
 
mysql_select_db($dbname) or die('database selection problem'); 
 
?>

+0

你不選擇一個表,這個表上運行一個查詢使用'mysql_ *'功能想 – Mihai

+0

停止。他們從PHP 7中刪除。使用[mysqli](http://php.net/manual/en/book.mysqli.php)或[PDO](http://php.net/manual/en/book.pdo .php)。 – Xorifelse

+0

我解決了問題,謝謝你的幫助 –

回答

0

首先,連接到你的數據庫(keinotis_iletisim)。例如:

$dbhost = "localhost"; // or any other address 
$dbuser = ""; // the user you created for the database in phpmyadmin 
$dbpass = ""; // the password you created for the database in phpmyadmin 
$dbname = "keinotis_iletisim"; 

然後,在查詢,你可以提一個表,例如:

SELECT * FROM tbl_uploads; 

Also see this link on W3Schools

2

您不需要選擇任何表,只需在存在表的數據庫上啓動查詢,就完成了。例如,

<?php 
    $dbhost = ""; 
    $dbuser = ""; 
    $dbpass = ""; 
    $dbname = ""; 

    mysql_connect($dbhost,$dbuser,$dbpass) or die('cannot connect to the server'); 
    mysql_select_db($dbname) or die('database selection problem'); 
    $query = "SELECT * FROM tbl_uploads;" 
    //executing the query and printing it's results 
    $results= mysql_query($query); 
    print_r($results); 
?> 

這將在變量$results中打印查詢結果。

注:

這個擴展被廢棄在PHP 5.5.0,它是PHP 7.0.0中刪除。相反,應該使用MySQLi或PDO_MySQL擴展。另請參閱MySQL:選擇API指南和相關FAQ以獲取更多信息。替代該功能包括:

+0

$結果在哪裏。並且plz不使用mysql_ *它的已棄用的 – devpro

+0

$結果是一個保存查詢結果的變量。你沒看到嗎?我也知道mysql_query()被刪除,但我在這裏提到它只是爲了設置一個示例,但無論如何,感謝告訴我,我會爲此添加一個註釋。 – SKG

+0

在ist更新中我沒有看到。現在看起來很好。 – devpro

0

您可以使用這樣

$sql = "SELECT * FROM MyGuests"; 
$result = mysql_query($conn, $sql); 

SQL語句現在,您可以通過使用

獲取的所有記錄選擇表
while($row=mysql_fetch_array($result)) 
{ 
    echo $row['column_name']; 
} 
0

這人會爲你工作

<?php 
//the connction 

$hostname_localhost = "localhost"; 
$database_localhost = "keinotis_iletisim"; 
$username_localhost = "root"; 
$password_localhost = ""; 
$localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR); 
?> 


<?php 


mysql_select_db($database_localhost, $localhost); 
$query_record = "SELECT * FROM tbl_uploads"; 
$record = mysql_query($query_record, $localhost) or die(mysql_error()); 
$row_record = mysql_fetch_assoc($record); 
$totalRows_record = mysql_num_rows($record); 

//echo $row_record['tbl_uploads_table_colum']; 

?> 

<!--And if you want to display the list--> 
<?php do { ?> 

<?php echo $row_record['tbl_uploads_table_colum']; ?> 

<?php } while ($row_record = mysql_fetch_assoc($record)); ?>