我正在尝试SQL
使用php
.
我收到一个错误:
Cannot Select Database (running local on XAMPP).
在XAMPP
我进入xampp-security
并将超级用户的密码更改为“thisthing”
我有一个名为:mydb.sql
mysql.sql:
CREATE TABLE `dpuForm` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`JN` TINYTEXT NOT NULL ,
`PN` TINYTEXT NOT NULL ,
`QTY` TINYTEXT NOT NULL ,
`DESC` TINYTEXT NOT NULL ,
PRIMARY KEY (`ID`) );
INSERT INTO 'dpuForm' ('JN',...........yadayadayada
这是我的php:
<?php
$host = "localhost";
$username="root";
$password="thisthing";
$database="mydb";
mysqli_connect($host,$username,$password);
@mysqli_select_db($database) or die( "Unable to select database");
$query = "SELECT * FROM dpuForm";
$result = mysqli_query($query);
$num = mysqli_numrows($result);
mysqli_close();
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table>
<th>Job Number</th>
<th>Part Number</th>
<th>QTY</th>
<th>Description</th>
<?php
$i=0;
while ($i < $num) {
$f1=mysqli_result($result,$i,"JN");
$f2=mysqli_result($result,$i,"PN");
$f3=mysqli_result($result,$i,"QTY");
$f4=mysqli_result($result,$i,"DESC");
?>
<tr>
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
</tr>
<?php $i++;} ?>
</table>
</body>
</html>