我在使用MySQL的页面上需要帮助解决错误。
当我尝试访问该网站时,会弹出以下文字:
Parse error: syntax error, unexpected 'mysql_connect' (T_STRING) in C:\xampp\htdocs\mywebsite\inc\scripts\mysql_connect.inc.php on line 11
<?php
$conn_error = 'Colud not connect.';
$mysql_host = "localhost:8080";
$mysql_user = "liam";
$mysql_pass = "";
$mysql_db = 'socialnetwork'
mysql_connect($mysql_host, $mysql_user, $mysql_pass or die("Couldn't Connect") ;
mysql_select_db('mysql_db') or die($conn_error);
echo 'Connected!'
?>
答案 0 :(得分:5)
$mysql_db = 'socialnetwork'
mysql_connect($mysql_host, $mysql_user, $mysql_pass or die("Couldn't Connect") ;
echo 'Connected!'
应该是
$mysql_db = 'socialnetwork';
^
mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Couldn't Connect") ;
^
echo 'Connected!';
^
Please, don't use mysql_*
functions in new code。它们不再被维护and are officially deprecated。请参阅red box?转而了解prepared statements,并使用PDO或MySQLi - this article将帮助您确定哪个。如果您选择PDO here is a good tutorial。
答案 1 :(得分:1)
这里是工作代码
<?php
$conn_error = 'Colud not connect.';
$mysql_host = "localhost:8080";
$mysql_user = "liam";
$mysql_pass = "";
$mysql_db = 'socialnetwork' ;
mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Couldn't Connect") ;
mysql_select_db('mysql_db') or die($conn_error);
echo 'Connected!' ;
?>
你有3个错误。
1-你忘记了;
$mysql_db = 'socialnetwork'
。
2-你忘记了)
mysql_connect($mysql_host, $mysql_user, $mysql_pass
。
3-您忘记了;
echo 'Connected!'
答案 2 :(得分:0)
忘记了
这里
$mysql_db = 'socialnetwork'