I'm having all sorts of trouble...
Here is the code I'm using:
$c = OCILogon('user', 'pass', 'host');
I get the following error:
PHP Warning: ocilogon(): ociopen_server: Error while trying to retrieve text for error ORA-12514 in D:\Inetpub\wwwroot**\oracle.php on line 26
Anyone know what the hell I'm doing wrong?
It's PHP4, IIS6 btw. I've tried this on PHP5, IIS7 as well, no luck.
Thanks for any help I can get... :(
You must have correctly configured TNSNAMES.ora file, where is stored information about connection to database. Oracle errorr ORA-12514 says:
TNS:listener does not currently know
of service requested in connect
descriptor
Function OCILogon have this syntax (I'am not PHP developer, so excuse me if I was not right):
resource oci_connect ( string
$username , string $password [,
string $connection_string [, string
$character_set [, int $session_mode
]]] )
In your example is on third position parametr "host". But manual says "connectin string".
This "connection string" must be coonfigured throught file $ORACLE_HOME/network/admin/tnsnames.ora file ($ORACLE_HOME is folder where is Oracle client installed).
TNSNAMES.ORA look like this(example):
TEST_DB = (DESCRIPTION =(ADDRESS_LIST
=(ADDRESS = (COMMUNITY = tcp.world)(PROTOCOL = TCP)(Host =
127.0.0.1)(Port = 1521)))(CONNECT_DATA = (SID = TESTDB_SID)))
Instead:
$c = OCILogon('user', 'pass', 'host');
You should use:
$c = OCILogon('user', 'pass', 'TEST_DB');
...TEST_DB is service name from tnsnames.ora file
And yet for complementing (my file $ORACLE_HOME/network/admin/sqlnet.ora look like this):
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
NAME.DEFAULT_ZONE = world
NAMES.DEFAULT_DOMAIN = world
And finally PHP manual example (connection string can be inserted directly into variables in PHP):
<?php
$db ="(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = HOSTNAMEHERE)
(PORT = 1521)
)
(CONNECT_DATA = (SID = SIDNAMEHERE))
)";
$odbc = ocilogon ('user', 'pass', $db) or die( "Could not connect to Oracle database!") or die (ocierror());
?>
try using persistant connection oci_pconnect()... worked for me
Related
I am still a programming newbie, please keep that in mind.
I installed SphinxSearch on Linux Mint. I followed instructions from a Digital Ocean tutorial. I created a configuration file (sphinx.conf) as follows:
source mySource{
type = mysql
sql_host = localhost
sql_user = root
sql_pass = mypass
sql_db = test
sql_query = SELECT id, uname FROM users
sql_attr_uint = id
sql_attr_string = uname
sql_port = 3306
}
index test{
source = mySource
path = /var/lib/sphinxsearch/data
docinfo = extern
}
searchd{
listen = 9306:mysql41
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
read_timeout = 5
pid_file = /var/run/sphinxsearch/searchd.pid
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
binlog_path = /var/lib/sphinxsearch/data
}
My PHP File
<?php
$conn = new mysqli('localhost','root','mypass','test',9306);
if($conn->connect_error){
die("Could not connect");
}else{
echo "You are connected!";
}
$query = $conn->query("SELECT * FROM test WHERE MATCH('hsmith')");
echo $query->error;
?>
PHP is throwing an error stating I am using a "Non-Object"
Any solution? Am I doing somethin entirely wrong?
Most likely the problem is in
$conn = new mysqli('localhost','root','mypass','test',9306);
As per http://php.net/manual/en/mysqli.construct.php when you pass 'localhost' in the 1st param mysqli tries to use unix socket, not a TCP socket and the port number therefore gets just ignored, i.e. you probably connect to your mysql instance instead of sphinx which then causes the problem you get.
Try:
$conn = new mysqli('127.0.0.1','','','test',9306);
instead.
Please also be aware that
echo $query->error;
is wrong since mysqli_result (http://php.net/manual/ru/class.mysqli-result.php) returned by query() does not have property 'error', you probably meant
echo $conn->error;
I am trying to connect to an oracle database on a remote server with php but it throws a warning: ora-12560 so I can't get connected with php but I can with toad for oracle, I am using odbc and I already set up my driver with microsoft odbc administrator:
I used odbc_connect(ConnectionString, UserID, UserPassword) in php
ConnectionString = Driver={Oracle en OraClient10g_home1};Server=xxx.xx.x.xxx;Port=1521;Database=xxxxxx;
I don't have access to the server where the database is located but I don't think the oracle service is down because I can connect with toad so it must be another thing. Here in my client I can make tnsping successful too.
Here is my tnsnames.ora
xxxxxx =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xx.x.xxx)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = xxxxxx)
)
)
Are you connecting to an Oracle RAC environment?
I have had issues like the one you describe when instance parameter local_listener is using a simplified notation like "dbnode-vip:1521" instead of "(ADDRESS=(PROTOCOL=TCP)(HOST=dbnode-vip)(PORT=1521))".
You can test this scenario by accessing the vip-address directly:
xxxxxx = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ip-of-the-dbnode-vip-address)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = xxxxxx) ) )
Another possible solution would be to utilize a newer version of your Oracle Client software. 10g is like Windows XP. Who uses such old de-supported software?
I keep getting this error:
Warning: mysql_connect(): Unknown MySQL server host 'elephant' (1) 4
My ini file is this:
[Database]
DBHostName = "localhost"
DatabaseName = "elephant"
DBUserName = "elephant"
DBPassword = "practice"
[Config]
ConfigTableName = "stage2_config"
Skin="purple"
My file that reads the ini file and gives the error is this on the line with the double bold stars. I have no idea what is going on here and why it says the host isn't localhost.
<?php
$gv_SystemTest = "<h2>system.php has been included</h2>";
$gv_SystemFileInfo = pathinfo(__FILE__);
$gv_SystemDirectory = $gv_SystemFileInfo['dirname'] . '/';
$gv_SystemINIpath = $gv_SystemDirectory . '';
$gv_SiteGlobals = parse_ini_file($gv_SystemINIpath . $_SERVER['WIA_SYSTEM_INI'], true);
function echoContent($p_ContentID) {
global $gv_SiteGlobals;
$fv_dbLink = mysql_connect($gv_SiteGlobals['Database']['DBHostName'],
$gv_SiteGlobals['Database']['DBUserName'],
$gv_SiteGlobals['Database']['DBPassword']);
**mysql_connect($gv_SiteGlobals['Database']['DatabaseName']);**
$fv_TheQuery = "select *from wia_content where content_id = $p_ContentID";
The function mysql_connect does not allow to select a database as you tried on this line.
mysql_connect($gv_SiteGlobals['Database']['DatabaseName']);
To connect and select a database, you need to use the function mysql_select_db in addition to mysql_connect.
$link = mysql_connect('host','username','password');
$selected = mysql_select_db('database_name', $link);
http://php.net/manual/en/function.mysql-select-db.php
Dont use mysql use only mysqli or pdo
I think you want to select db
to select db you should be mysql_select_db()
mysql_select_db('foo', $link);
your error in this line
mysql_connect($gv_SiteGlobals['Database']['DatabaseName']);
it should be of the form
mysql_connect('localhost', 'mysql_user', 'mysql_password');
This question already has answers here:
How to change mysql to mysqli?
(12 answers)
Closed 3 months ago.
I have some existing PHP code that is now throwing a fatal error since we migrated to PHP 7.0. Using this Stackoverflow Question I've altered this line:
$link = mysql_connect($host.':'.$port, $user, $pass) or die("Can not connect." . mysql_error());
to this:
$link = new mysqli($host.':'.$port, $user, $pass);
I am now throwing this error which I guess is some progress. The syntax seems fine? What am I missing?
Warning: mysqli::__construct(): (HY000/2002): Connection timed out
The constructor class looks like this:
__construct (
[ string $host = ini_get("mysqli.default_host")
[, string $username = ini_get("mysqli.default_user")
[, string $passwd = ini_get("mysqli.default_pw")
[, string $dbname = ""
[, int $port = ini_get("mysqli.default_port")
[, string $socket = ini_get("mysqli.default_socket") ]]]]]] )
So the order is host, username, password, database, port, socket. You'll need to pass in the port in a separate variable:
$link = new mysqli($host, $user, $pass, null, $port);
Edited because I copied the wrong bit of code..
Try just using the function.
$link = mysqli_connect($host,$user,$pass,$db).
The order is host, user, pass, db
http://php.net/manual/en/function.mysqli-connect.php
I have an android app that i am trying to get connected to my SQL Server.
I have tried countless ways of getting it to work by get a error on my sqlsrv_connect.
Here is the php im tyring to use. I have replaces my read server/credentials with *
<?php
$myServer = "***";
$myUser = "***";
$myPass = "***";
$myDB = "***";
//connection to the database
$conn = sqlsrv_connect($myServer, array('UID'=>$myUser, 'PWD'=>$myPass, 'Database'=>$myDB));
$_GET['search'];
//declare the SQL statement that will query the database
$query = "SELECT * FROM dbo.JD";
$data = sqlsrv_query($conn, $sql);
$result = array();
do {
while ($row = sqlsrv_fetch_array($data, SQLSRV_FETCH_ASSOC)){
$result[] = $row;
}
}while ( sqlsrv_next_result($data) );
echo(json_encode($result));
sqlsrv_free_stmt($data);
mssql_close($dbhandle);
?>
When processing on a php online test i get this error
Fatal error: Call to undefined function sqlsrv_connect() in [...][...]on line 7
Here my my php info
http://www.bakerabilene.com/phpinfo.php
It shows sqlsrv as a Registered PHP Streams so I don't understand why its not working.
I have also stripped my php down to where it just makes the connection to see if anything was causing the issue, but it still gives me that same error.
I am positive my server/user/pass/db are correct because i use the exact same credentials on my aspx webpage to access SQL server.
Check if the Native SQL Driver (Microsoft Drivers 3.0 for PHP for SQL Server) is installed . Have you asked the Godaddy Team about this ?