Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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/63.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
Php 学习如何从MYSQL读取数据_Php_Mysql - Fatal编程技术网

Php 学习如何从MYSQL读取数据

Php 学习如何从MYSQL读取数据,php,mysql,Php,Mysql,我试图学习php和mysql,我试图从我的数据库中读取数据,在那里我在线跟踪了一些东西,遇到了一个错误,这是我的代码 <?php include 'includes/conn.php'; $query =sprintf("Select * from customer"); $result = mysql_query($query); if (!$result) { $message ='from you see this then it's not

我试图学习php和mysql,我试图从我的数据库中读取数据,在那里我在线跟踪了一些东西,遇到了一个错误,这是我的代码

<?php
  include 'includes/conn.php';

   $query =sprintf("Select * from customer");
   $result = mysql_query($query);

   if (!$result) 
   {
   $message  ='from you see this then it's not connecting!'.mysql_error() ."\n";
      $message .= 'everything' .$query;
      die($message);
   }   

    while ($customer = mysql_fetch_assoc($result))
    {
       echo $row['cust_id'];
       echo $row['fname'];
       echo $row['lname'];
       echo $row['gender'];
       echo $row['dob'];
    }
mysql_free_result($result);
?>

替换

$message  ='from you see this then it's not connecting!'.mysql_error() ."\n";
这里您的字符串是
中的单引号,它是造成问题的原因

$message  ="from you see this then it's not connecting!".mysql_error() ."\n";

…要显示结果,请更改以下内容:

while ($customer = mysql_fetch_assoc($result))
为此:

while ($row = mysql_fetch_assoc($result))
请查看下面的示例,了解如何使用php读取my mysql数据。
$sql=“从MyGuests中选择id、firstname、lastname”;
$result=mysqli\u查询($conn,$sql);
如果(mysqli_num_行($result)>0){
//每行的输出数据
while($row=mysqli\u fetch\u assoc($result)){
echo“id:.$row[“id”]。-Name:.$row[“firstname”]。$row[“lastname”]。
”; } }否则{ 回显“0结果”; }
第一个错误就在这里
$message='从您看到的这个,然后它就不连接了!'。mysql\u错误()。“\n”“并遇到错误”-那么您遇到了什么错误?你想让我们猜猜看吗?告诉我们!不要使用mysql函数,然后调试您自己的$con=mysql\u connect($dbhost,$dbuser,$dbpass)或die(mysql\u error());等您可以在php.netUse IDE上找到带有代码高亮显示的示例
while ($row = mysql_fetch_assoc($result))
Please review the below example for reading data my mysql using php.    

$sql = "SELECT id, firstname, lastname FROM MyGuests";
    $result = mysqli_query($conn, $sql);

    if (mysqli_num_rows($result) > 0) {
        // output data of each row
        while($row = mysqli_fetch_assoc($result)) {
            echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
        }
    } else {
        echo "0 results";

}