ดูเหมือนว่าฉันไม่สามารถรันโค้ดนี้ภายใต้โลคัลโฮสต์ได้ เป้าหมายของฉันคือสร้างตารางที่ควรจะแสดงบนเว็บไซต์ แต่เมื่อฉันพยายามเชื่อมต่อ ฉันได้รับข้อผิดพลาด:
คำเตือน: mysql_connect(): ใน C:\xampp\htdocs\PhpProject2\hent.php ออนไลน์ 5 ไม่สามารถเชื่อมต่อได้
my site name: http://localhost/PhpProject2/hent.php
รหัส:
<html>
<body>
<?php
mysql_connect('<server is here>','<my username here>','<password here>')
or die('can not connect' );
mysql_select_db('<my username here>') or die ('can not connect to <username here>');
$sql = "Select * from Customer";
$result = mysql_query($sql);
$number= mysql_num_rows($result);
for($i=0; $i < $number; $i++)
{
$table = mysql_fetch_row($result);
echo $table[0], $table[1];
echo '<br>';
}
?>
</body>
</html>
ฉันใช้ xampp และ MySQL ทำงานบนพอร์ต 3306:]
แทนที่จะเป็น ‹ ชื่อผู้ใช้ที่นี่ >, ‹ เซิร์ฟเวอร์อยู่ที่นี่ >, ‹ รหัสผ่านที่นี่ > มีรหัสจริง :]
ฉันขอขอบคุณคำตอบใด ๆ :]