php - Show a Parse error: "@" on dbc connect. how i fix it? -


this question has answer here:

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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -