刚刚完成了在Macbook上安装MySQL的工作,以完成我的Web开发作业。我正在使用Macintosh HD / Library / WebServer / Documents /上的mac网络服务器运行网页。当我尝试使用以下代码从终端执行php文件以在数据库中创建表时,在下面也出现错误。
使用“ php fileName.php”从终端执行的代码:
<?php
$mysqli = new mysqli(localhost, root, ****, lab7);
$query = "CREATE TABLE products (ID int primary key)";
$mysqli->query($query);
$mysqli->close();
?>
错误:
Warning: mysqli::__construct(): (HY000/2002): No such file or directory in /Library/WebServer/Documents/week7/Lab7/CreateTableTest.php on line 2
Warning: mysqli::query(): Couldn't fetch mysqli in /Library/WebServer/Documents/week7/Lab7/CreateTableTest.php on line 6
Warning: mysqli::close(): Couldn't fetch mysqli in /Library/WebServer/Documents/week7/Lab7/CreateTableTest.php on line 8