出于某种原因,我很难让我的PDO连接正常工作。我输入了正确的主机,用户名和密码,允许我进入同一个数据库,但是其他表。
我的连接设置如下,除了输入的实际用户名,密码和数据库。我已经检查了10次,这是正确的信息。
我在错误报告文件中收到的最新错误是:
[25-Oct-2016 13:22:07 America / Chicago] PHP Parse错误:语法错误,意外'$ servernameCon'(T_VARIABLE)
我已将localhost更改为专用IP地址,我不需要对我的网站上的任何其他连接进行更改,即使这样做仍然无济于事。
我因为我做错了而感到茫然。有人看到我遗失的任何东西吗?
$servernameCon = 'localhost';
$usernameCon = ' ';
$passwordCon = ' ';
$con = new PDO('mysql:host='.$servernameCon.';dbname= ', $usernameCon, $passwordCon);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
在$ servernameCon之前:
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once 'core/init.php';
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
if(Input::exists()) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'firstname' => array(
'required' => true,
'min' => 2,
'max' => 50
),
'lastname' => array (
'required' => true,
'min' => 2,
'max' => 50
),
'email' => array (
'required' => true,
'min' => 2,
'max' => 50
),
'phone' => array (
'required' => true,
'min' => 7,
'max' => 12
),
'network' => array (
'required' => true
),
'birthday' => array (
'required' => true
),
'username' => array(
'required' => true,
'min' => 4,
'max' => 20,
'unique' => 'users'
),
'password' => array(
'required' => true,
'min' => 6
),
'password_again' => array(
'required' => true,
'matches' => 'password'
)
));
if($validation->passed()) {
$user = new User();
$salt = Hash::salt(32);
try {
$user->create(array(
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'email' => Input::get('email'),
'phone' => Input::get('phone'),
'network' => Input::get('network'),
'birthday' => Input::get('birthday'),
'username' => Input::get('username'),
'password' => Hash::make(Input::get('password'), $salt),
'salt' => $salt,
'joined' => date('Y-m-d H:i:s'),
'group' => 1
));
($user->lastId);
//Add user to posts table
if(isset($_POST['submit'])){
$id = ( isset( $_SESSION['id'] ) ? $_SESSION['id'] : "" );
$user_id = $user->lastId;
$posts = 0;
$conversations = 0;