我显然对PHP很陌生,我的朋友已经要求我创建一个可以持续使用的动态博客。我希望它连接到phpMyAdmin所以它会更容易,但是当我尝试将它连接到我的网页时,它总是会失败并且出现我的设置错误。我不知道该怎么做才能帮助我。如果我不清楚,我很抱歉。如果您希望我更详细地发布,请发布。
这是我的代码:
<?php
$dbhost = 'localhost';
$dbuser = ' root';
$dbpass = '';
$dbname = 'blog1';
$connect = mysqli_connect($dbname, $dbuser, $dbhost, $dbpass) or die ('Cannot connect to database.');
echo "Succesfully connected to database!";
?>
答案 0 :(得分:0)
测试本
<?php
$dbhost = 'localhost';
$dbuser = ' root';
$dbpass = '';
$dbname = 'blog1';
$connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Cannot connect to database.');
echo "Succesfully connected to database!";
以错误的方式调用了mysqli_connect()。
答案 1 :(得分:0)
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root123';
$dbname = 'mydb';
$connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Cannot connect to database.');
如果在localhost上运行PHPMyAdmin,请在文件中取消注释:
sudo gedit /etc/php5/apache2/php.ini
这一行: mysqli.allow_local_infile =开启
重启Apache:
sudo /etc/init.d/apache2 restart or sudo service apache2 restart