数据库选择(PHP)

时间:2016-02-27 09:45:47

标签: php mysql database selection

如何在数据库中选择tbl_uploads表?

PHPMYADMİNIMG

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');
?>

4 个答案:

答案 0 :(得分: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指南和相关的常见问题解答以获取更多信息。该功能的替代方案包括:

答案 1 :(得分: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 :(得分:0)

您可以使用sql语句选择您的表,如下所示

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

现在您可以使用

获取所有记录
while($row=mysql_fetch_array($result))
{
     echo $row['column_name'];
}

答案 3 :(得分: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)); ?>