I'm developing a website in PHP that interacts with Oracle10g remote server database. I've googled on this topic a lot and couldn't find a solution, though i got some idea on tnsnames.ora file. I've installed WAMP in my machine. What are steps to connect to Oracle remote database?? Can any one explain it step by step??
I created a site which connects to MySQL datebase a year ago which wasn't this much tough.
$con = oci_connect('username', 'password', '//server ip:port/service name');
It's throwing "Call to undefined function oci_connect()" error.
First of all , you must install and configure OCI8.
To do this please, follow this link http://antoine.hordez.fr/2012/09/30/howto-install-oracle-oci8-on-rhel-centos-fedora/
To connect to database :
$Conexion_ID =oci_connect($OracleUser, $OraclePassw, $OracleIP);
To launch a query
$sql="SELECT ...";
$id_sentence = oci_parse($Conexion_ID, $sql);
if (!$id_sentence)
{
return false;
}
$results = oci_execute($id_sentence, OCI_DEFAULT);
To view results:
while ($row = oci_fetch_array($id_sentence, OCI_ASSOC+OCI_RETURN_LOBS))
{
....
}
Related
I need to know if it's possible to Create an Event in MySQL with its code statement using Load Data In file syntax.
Here's my current situation.
I can get the database (MS Access) using PHP from a Local Biometric Database.
I have updated the database in my Local Database Server which is MySQL now.
I can update my target Online Database Server via Exporting it first then Importing the database in the Online Database Server.
My Main Question is how I can manage this without any user interaction
such as MySQL Event Features?
I am trying to upload a data from my PC (Local server) into our Domain (Web Server)
Already done this guys, What i did is I've built a local application to my local server at our office then that application is doing a FTP service to upload the updated database from our Local Biometric Database into the online web server.
Once all this is done, I've created a php script which will load the .SQL file using a Cron Job. You all know cron job are time scheduled events for controlling scripts and doing other linux command.
I'll share my code of php file so everyone who encounter this can use this in the future.
date_default_timezone_set('Asia/Taipei');
$CurTime = date('Y-m-d H:i:s');
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link){
die('Failed to connect to server: ' . mysqli_error());
}
//Select database
$db = mysqli_select_db($link,DB_DATABASE);
if(!$db){
//Do auto download of database in the Server automatically
if(file_exists('Database/'.DB_DATABASE.'.sql')){
mysqli_query($link,"CREATE DATABASE ".DB_DATABASE);
$db = mysqli_select_db($link,DB_DATABASE);
$readContent = file_get_contents("Database/".DB_DATABASE.".sql");
$res = mysqli_multi_query($link,$readContent) or die(mysqli_error($link));
mysqli_close($link);
} else {
die("Unable to select database, Please call your system administrator. Thank you.");
}
}
function Reload_Database($DBLink){
if(file_exists($DBLink)){
//mysqli_query($link,"DROP DATABASE ".DB_DATABASE);
//mysqli_query($link,"CREATE DATABASE ".DB_DATABASE);
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
$db = mysqli_select_db($link,DB_DATABASE);
$readContent = file_get_contents($DBLink);
$res = mysqli_multi_query($link,$readContent) or die(mysqli_error($link));
mysqli_close($link);
return 'Database Reloaded';
} else {
die("Unable to reload database, Please call your system administrator. Thank you.");
}
}
echo Reload_Database('../employee/database/'.DB_DATABASE.'.sql');
This is basic script that will reload the database of the uploaded database given from my local application.
From here the cron job will do its part. Expect that my local application is also a service that will just do the uploading of the updated database of the Local Biometric Database.
I currently have a very big problem with PHP and mySQL. I moved a System I coded to a new Server. And while everything worked fine on the old Server, I had some problems on the new Server. Especially with mySQL. While I solved nearly all of them, I have one which I can't seem to get a hold on. And after 2 hours of trying i searched on the Internet for another two hours and updated my Syntax several times. But nothing seems to work. So now I'm here. I get a Connection to the database without a problem, but I can't update the values. I hope you can help me.
//Connect to mySQL Database
$verbindung = mysql_connect($server, $username, $passwort);
if (!$verbindung) {
echo "Couldn't connect: " . mysql_error();
}
$name=$_POST['fuehrer'];
$ident=$_POST['id'];
//Debugging
echo $name;
echo $ident;
$sql_befehl_0="UPDATE 'olgatermine' SET fuehrer = '".$name."' WHERE ID = '".$ident."';";
if (!mysql_query($verbindung, $sql_befehl_0)){
echo "Couldn't write to database";
}
//Close connection
mysql_close ( $verbindung );
What version of php use? Because in the newest versions of php the mysql functions are deprecated/removed, use instead mysqli.
Try to echo a mysqli_error at the end of the code, also mysql_error if your version of php accepts mysql functions.
If not version of php is the problem check this:
Wrong things what i see in your code..:
$sql_befehl_0="UPDATE 'olgatermine' SET fuehrer = '".$name."' WHERE ID = '".$ident."';"; // wrong
should be:
$sql_befehl_0="UPDATE `olgatermine` SET `fuehrer` = '".$name."' WHERE ID = '".$ident."';";
You need to run mysql_select_db('dbname') below line you do the mysql connection.
You can set at the first line of file:
ini_set('display_errors',1);
error_reporting(E_ALL);
to show all errors.
I have to build an android app which connects to a remote MYSQL webserver and retrieve information for display purpose.
So I did research coz I had no idea where to start. I read an article it mentions the better approach for that is to use php script. And didn’t know anything about how server, database and php works, so I studied php from here “http://www.homeandlearn.co.uk/php/php12p1.html” to understand and downloaded WhampServer to do some testing. On local machine everything worked fine.
But main thing I don’t understand is “HOW TO CONNECT TO REMOTE SERVER/DATABASE”.
It’s obvious that I’m doing something really stupid, I just need help to find out what am I doing wrong.
When we test php script on local machine in webrowse we use "localhost/some.php." But when I want to test same php script on remoter server from my local machine then what and how should I do? Do I need to make some changes in configuration file on server side?
I have done more research before asking this question here to understand remote server connection in php but I still don’t understand. I have gone through almost all the pages within the link below:
https://www.google.co.uk/search?q=connect+to+remote+mysql+webserver+php&rlz=1C1AVSX_enGB447GB448&oq=connect+to+remote+mysql+webserver+php&aqs=chrome.0.69i57j69i62l3.19724j0&sourceid=chrome&ie=UTF-8#fp=5a2359cf96dc5f79&q=how+to+connect+to+remote+mysql+web+server+php
And help would be much appreciated.
If my question is not clear please let me know I'll try to explain more. or think of it as if you have to connect to a remote MySQL server how would you do , means what is the process and steps involved in that.
Thanks everyone.
Edit
I have created a database "dealt3_raj_test" on remote server. and when I type "examplewebserver.CO.UK/myphpscriptname" in my web browser.
It gives me error "An error occurred , You have reached the error page"
<?PHP
$user_name = "dealt3_raj";
$password = "5dN5nh&eMd(vCR$dzk";
$database = "dealt3_raj_test";
$server = "examplewebserver.CO.UK";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if($db_handle)
{
print "Connected";
}
else
{
print "Can not connect to server";
}
if ($db_found)
{
print "DataBase found";
}
else
{
print "DataBase not found";
}
?>
Adding onto #user4035's comment, after opening the connection, use JDBC in your Android/Java code to interact with the database.
That said, it is not good practice. Rather create a web service
Your application may experience latency/connectivity issues. This will impact performance.
Your MySQL server will have to be open to remote connections which is strongly advised against
If your Android App is intended for public usage, it means the database username and password of your MySQL server reside on everyone's phone using your app. Encrypted or not this makes your database server a "step less" secure
Well answered here on SO (JDBC vs Web Service for Android)
use this code to connect with data base
$username = "database user name";
$password = "DB password";
$hostname = "hostname";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
//select a database to work with
$selected = mysql_select_db("data base name",$dbhandle) or die("Could not select examples");
I want to connect MySQL database using PDO Extension. I am using PHP 5.4
$db = new PDO('mysql:host=localhost:8080;dbname=films_db;charset=UTF-8', 'root', '');
$query = "SELECT * FROM employee";
$result = $db->query($query);
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
print_r($row);
}
$result->closeCursor();
But, my WAMP server is not responding. I am not getting any result. Its "Waiting for localhost" state and getting server timeout error.
Pls help me to resolve this. Thanks.
Port 8080 is for http,
normally it does not used for mysql.
and the default mysql port is 3306.
You might need to check your mysql setting to "confirm" the actual port being used.
Beside this, you might need to check how many record in the table employee.
If millions of records, it might be the reason it takes time to load.
I am new to Joomla and new to php (wish I was so new in age too). I have installed joomla on a local apache webserver. I am trying to use some php code in a joomla article in order to fetch some data from a Sybase ASE 12.5 database. I installed sourcerer and started to try an ODBC connection using a system DSN (which I verified it is working):
{source}
<?php
echo 'This text is placed through <b>PHP</b>!';
echo '<p>';
echo '</p>';
$conn = odbc_connect('myDSN', 'sa', 'myPassword') or die('Could not connect !');
echo 'Connected successfully';
$sql = 'SELECT day, name FROM my_table where month = 1';
odbc_close($conn);
?>
{/source}
The above code doesn't do much, but this is how far I can get without problems. I refresh the joomla page and I see inside the article's text:
...
This text is placed through PHP!
Connected successfully
...
Seems ok, the connection obviously established (I verified this by stopping the sybase service and getting the "Could not connect" message). Then I added one more line, just below the $sql assignment.
$rs = odbc_exec($conn,$sql);
I refresh and ...I see nothing coming from the script (not even the "This text is placed through PHP!").
Obviously, I see nothing if I include code to echo the contents of $rs. I also tried this but in vain.
if (!$rs)
{exit("Error in SQL");}
Once I add the odbc_exec command, the entire script ceases working.
In php.ini I read:
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
Do you have any idea what is going wrong?
UPDATE
Connecting to a MySQL database using code like this, works like a charm.
To answer your question
Is this the correct way to get data
from another database in to an article
or should I use some plug-in to do
that?
The correct way is to use JDatabase object which you get by JFactory::getDBO() or JDatabase::getInstance(), see Joomla JDatabase documentation.
$db = JDatabase::getInstance( $databasConfigArray );
$db->setQuery('your query');
$data = $db->loadObjectList();
Here is a good tutorial showing how to connect to multiple databases in Joomla, there is even source code for helper class.
Also look at this thread Connecting to 3rd party databse in Joomla!?