语法错误,意外的"mysql_connect"(T_STRING) [英] syntax error, unexpected 'mysql_connect' (T_STRING)

查看:176
本文介绍了语法错误,意外的"mysql_connect"(T_STRING)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用MySQL的页面上出现错误时,我需要帮助.

I need help with an error on my page using MySQL.

当我尝试访问该网站时,会弹出以下文本:
Parse error: syntax error, unexpected 'mysql_connect' (T_STRING) in C:\xampp\htdocs\mywebsite\inc\scripts\mysql_connect.inc.php on line 11

When I try to go to the website, this text pop up:
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!'
?>

推荐答案

$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!';
                 ^

请不要在新代码中使用mysql_*函数.它们已不再维护并已正式弃用.看到红色框?了解有关 准备好的语句 的信息,并使用 MySQLi -本文将帮助您确定哪一个.如果您选择PDO,这里是一个很好的教程.

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

这篇关于语法错误,意外的"mysql_connect"(T_STRING)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆