1

I am using SQLplus and zend server. When I try to run config.php, I get the error. I dont know whats causing it. This the code of config.php

<?php

$host="jojo"; // Host name 
$username="system"; // Mysql username 
$password="a1234"; // Mysql password 
$db_name="project_db1"; // Database name 


//Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); 
mysql_select_db("$db_name")or die("cannot select DB");

?>

I tried to replace the above code and made connection using the following code:

$conn= oci_connect("system" , "a1234" , "(DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = jojo)(PORT = 1522))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcale)
    )
  )");

The connection problem was solved but now

mysql_select_db("$db_name")or die("cannot select DB");

this line of code is giving the same error, i.e "connection cannot be made target machine actively refused it". I dont understand what the problem is. Why it is not connecting using mysql_connect.

el323
  • 2,760
  • 10
  • 45
  • 80
  • This is probably a setup problem on the sql server. Side note - you don't have to quote variables. So, `mysql_connect("$host", "$username", "$password")` should just be `mysql_connect($host, $username, $password)` – Stephen Jul 27 '14 at 20:47
  • 1
    Just to be literal, this `$host="jojo";` you're not actually using that, are you? Usually it's `$host="localhost";` or `$host="sql.example.com";` – Funk Forty Niner Jul 27 '14 at 20:51
  • 1
    Using `mysql_connect()` is now deprecated (see [here](http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli)). – Pith Jul 27 '14 at 20:57
  • Is your database server on the same ip as the script you are running? – dave Jul 27 '14 at 21:08

2 Answers2

0

oci_connect is a different API - its for ORACLE databases and mysql_connect is for MYSQL databases. I think you're mixing up quite a few things here, additionally : you forgot both the port and the database in mysql_connect.

you need to use these functions exclusively : http://php.net/manual/en/ref.oci8.php

http://php.net/manual/en/book.oci8.php

specializt
  • 1,913
  • 15
  • 26
0

You can also use the easy syntax like so:

$host="jojo"; // Host name 
$port = "1522"; //Port number
$username="system"; // Mysql username 
$password="a1234"; // Mysql password 
$db_name="project_db1"; // Database name 
oci_connect("$username","$password", "$host:$port/$db_name");
raidenace
  • 12,789
  • 1
  • 32
  • 35