When I am trying to connect to local host, it is working fine. But once I am connecting to navicat address it's giving error. Please help me, i am not sure if i am missing anything

Local host working code:

<?php
//connect to mysql db
$con = mysqli_connect("localhost","root","","ros");
//connect to the service orders database
mysqli_select_db($con, "ros") or die('Could not connect: ' . mysql_error());

Not working code:

<?php
//connect to mysql db
{
$link = mysql_connect("50.98.141.10:3306","root","password","db_name");
or die('Could not connect: ' . mysql_error());

Error Coming as:

( ! ) Parse error: syntax error, unexpected 'or' (T_LOGICAL_OR) in C:\wamp64\www\dummy.php on line 5

    Remove the semi-colon on the preceding line.

    Of course, you really should not be using the deprecated mysql() functions, and instead either using the mysqli() functions or the PDO extension. 😉

      Tried this below and now getting this error : Parse error: syntax error, unexpected 'mysqli_select_db' (T_STRING) in C:\wamp64\www\dummy.php on line 5

      <?php
      //connect to mysql db
      {
      $link = mysqli_connect("50.98.141.10:3306","root","password","ros")
      mysqli_select_db($con, "ros") or die('Could not connect: ' . mysql_error());
      }

        In that case, you need the semi-colon command terminator after the [FONT=Courier New]mysqli_connect()[/FONT] call. The reason you didn't want it in the prior example was that you wanted to append the [FONT=Courier New]or die();[/FONT] to the end of the other function.

          Your localhost connection code uses mysqli functions to connect and your other code uses the old, deprecated mysql functions. Furthermore, the localhost code calls the connection $con and the other code calls it $link instead.

            Obviously, the "localhost" box has the mysqli extension to PHP installed. Does the server at 50.98.141.10 also have this extension installed? (hint: <?php phpinfo(); ?>)

            If mysqli is installed on the remote server, you should use mysqliblahblah() everywhere. No mysqlblahblah() is required, needed, or even wanted.

            Next, look at the signature of the [man]mysqli_connect/man function:

            $link = mysqli_connect($host, $user, $password, $database_name); //the name of the database is given in the function!

            So, there's never any reason to call [man]mysqli_select_db/man in PHP unless you're switching from one database to another in the same script. Note also that [thread=10395565]over here in this thread[/thread] we're talking about how we typically make multiple connection variables or objects to connect to separate databases (a tad more advanced subject than what we're discussing here though).

              Thanks, got it fixed

              dalecosp;11061541 wrote:

              Obviously, the "localhost" box has the mysqli extension to PHP installed. Does the server at 50.98.141.10 also have this extension installed? (hint: <?php phpinfo(); ?>)

              If mysqli is installed on the remote server, you should use mysqliblahblah() everywhere. No mysqlblahblah() is required, needed, or even wanted.

              Next, look at the signature of the [man]mysqli_connect/man function:

              $link = mysqli_connect($host, $user, $password, $database_name); //the name of the database is given in the function!

              So, there's never any reason to call [man]mysqli_select_db/man in PHP unless you're switching from one database to another in the same script. Note also that [thread=10395565]over here in this thread[/thread] we're talking about how we typically make multiple connection variables or objects to connect to separate databases (a tad more advanced subject than what we're discussing here though).

                Write a Reply...