-3

I just wanna ask for your help guys. Im having a problem with my coding which is to open database connection. Here is my code.

<?php

define('MYHOST', 'localhost');
define('MYDATABASE', 'system');
define('MYUSERNAME', 'root');
define('MYPASSWORD', 'root');


$conn = mysql_connect("localhost", "root", "", "")

if ($mydb->connect_error) {

  die("Connection Error Message: ".$mydb->connect_error);
 }

?>  

and it show an error like this

Parse error: syntax error, unexpected 'if' (T_IF) in C:\xampp\htdocs\system\database.php on line 11

thank you guys for your answer..

Jees K Denny
  • 531
  • 5
  • 27
typo
  • 33
  • 6

3 Answers3

1

This extension (mysql_) was deprecated in PHP 5.5.0, please use mysqli or PDO(PHP Data Objects) instead.

If your PHP versional lower than 5.5.0, you can edit this line:

$conn = mysql_connect(MYHOST, MYDATABASE, MYUSERNAME, MYPASSWORD);

to replace this:

$conn = mysql_connect("localhost", "root", "", "")
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
Chris.C
  • 297
  • 3
  • 17
0

try this one

$conn = mysql_connect("localhost", "root", "");
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • 1
    Why should the OP "try this"? A ***good answer*** will always have an explanation of what was done and why it was done in such a manner, not only for the OP but for future visitors to SO. – Jay Blanchard Oct 20 '16 at 17:17
0

There are two errors in the your code:

  • You are missing the semicolon(;) in the line number 11 .
  • You are using the invalid variable for the connection($mydb), replace it with ($conn).

Try the below script, hope this helps:

<?php

    define('MYHOST', 'localhost');
    define('MYDATABASE', 'system');
    define('MYUSERNAME', 'root');
    define('MYPASSWORD', 'root');


    $conn = mysql_connect("localhost", "root", "", "");

    if ($conn->connect_error) {

      die("Connection Error Message: ".$conn->connect_error);
     }

    ?>
VishalParkash
  • 490
  • 3
  • 15