php - Show a Parse error: "@" on dbc connect. how i fix it? -
this question has answer here:
- php parse/syntax errors; , how solve them? 11 answers
error - "parse error: syntax error, unexpected '@' in /home/vol2_8/byethost13.com/b13_16347614/digiquiz.my-style.in/htdocs/simplephpquiz-master/includes/db_conn.php on line 7"
here code:
<?php // set database access information constants define ('db_user', 'xxxxxxxxx'); define ('db_password', 'xxxxxxx'); define ('db_host', 'xxxxxxxxxxx'); define ('db_name', 'xxxxxxxxxxx'); @ $dbc = new mysqli(xxxxxxxxxx, xxxxxxxx, xxxxxxxxx, xxxxxxxx); // details added constants not define's if (mysqli_connect_error()){ echo "could not connect mysql. please try again"; exit(); } ?>
why not using defines so:
<?php //set database access information constants define ('db_user', 'xxx'); define ('db_password', 'xxx'); define ('db_host', 'xxx'); define ('db_name', 'xxx'); @ $dbc = new mysqli(db_host, db_user, db_password, db_name); if (mysqli_connect_error()){ echo "could not connect mysql. please try again"; exit(); }
remove @ next $dbc (invalid syntax).
@ $dbc = new mysqli(db_host, db_user, db_password, db_name);
consider using below check error using variable mysqli class:
if ($dbc->connect_errno) { printf("connect failed: %s\n", $dbc->connect_error); exit(); }
all should this:
<?php //set database access information constants define('db_user', 'xxx'); define('db_password', 'xxx'); define('db_host', 'xxx'); define('db_name', 'xxx'); $dbc = new mysqli(db_host, db_user, db_password, db_name); if ($dbc->connect_errno) { printf("connect failed: %s\n", $dbc->connect_error); exit(); }
Comments
Post a Comment