dear all..
i have a DB which built use Mysql.
for this case, i want to access another server PC which have DB in firebird. i want to take some data inside that. Both of DB always connected, because i must get data every time. This is a scheduling data, so i must always connected to firebird from mysql.
But i have no experience to make connection between Mysql and firebird.
can you tell me how to do that?
what is the best way that must i choose, do some migration or convert or may make sync.?
any advance will be appreciate.thanks.
could I call the firebird 1st(use ibase_connect) then insert the data to mysql? i dont know how to insert data to Mysql DB after i get from firebird DB.
At this MySQL server can only connect to other MySQL servers. Not sure about Firebird, but if it's similar, then you need to do all you data handling in external application.
Take a look at MySQL Migration Toolkit. According to this post firebird is supported.
Cheers!
I suggest migrating firebird data to MySQL, this would help you avoid some pain in the ass :)
Unfortunately I have a project which has to be synced with some external firebird db...
may be use php can work.
<HTML>
<HEAD>
<TITLE>PHP + Firebird / Interbase test (connection)</TITLE>
</HEAD>
<BODY>
<H3>FB Connect test.</H3>
<?php
// DB definition of account
define("DBNAME","xx.xxx.xx.xxx:D:\DATABASE\OCS DATA.FDB"); // data bsse name
define("DBUSER","SYSDBA"); // user name
define("DBPASS","masterkey"); // password
// DB connection
$dbh = ibase_connect(DBNAME,DBUSER,DBPASS);
if ($dbh == FALSE) {
echo 'could not connect to DB<BR>';
} else {
echo 'success to connect to DB<BR>';
// DB dis connection
ibase_close($dbh);
}
?>
</BODY>
</HTML>
Related
I have searched on many different sites and cannot find an answer that specifically answers this question:
I have WAMP Server installed, which installed phpmyadmin as well as MySQL. I can easily connect to the database through php/pdo by using localhost as my hostname.
But my problem is I am trying to connect to a database that I have exported from phpmyadmin as "mydatabase.sql". So now lets say I placed this file on my pc at "C:\Users\Username\Desktop\MyFolder\mydatabase.sql". How would I connect to this database (if this is possible)?
The reason is that I cannot install WAMP Server on all the pcs that would use this program. so would like to be able to connect to the database without having to install any type of servers, etc...
My php at the moment is:
<?php
$dsn='mysql:C:\Users\Username\Desktop\MyFolder\mydatabase.sql';
$username='username';
$password='pass';
try
{
$dbh = new PDO("$dsn",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo 'Connected to Database<br/>';
$sql = "SELECT * FROM users";
foreach ($dbh->query($sql) as $row)
{
echo $row["ID"] ." - ". $row["Name"] ."<br/>";
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Also, if this is possible, would username and password be necessary to connect to an "off server database"?
If I try:
$dsn='sqlite:C:\Users\Optique\Desktop\optique.sql';
I get:
"Connected to Database
SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database"
But I think that is because SQLite uses a different database format than MySQL (stand to be corrected). So what I need is something similar to the SQLite driver for MySQL.
Thanks in advance!
You cannot find an answer simply because it doesn't exist: it's impossible to connect to an SQL dump through PDO, and it makes no sense anyway: a dump is not a database but simply a collection of INSERT queries. Unlike sqlite, for mysql you need a server to connect with.
To be able to connect, you should import that dump into mysql database first and then connect to that database with PDO.
I am connecting to my database using this command:
$resource = new PDO('odbc:driver=FreeTDS;Server=127.0.0.1;Port=8090;UID=Reporting;PWD=readonly;');
There is no dbname specified, and yet, it still connects to a database. The problem is, it is connecting to the wrong database. I tried including a section dbname=DATABASENAME;, but this was entirely ignored. How do I tell PDO to connect to a different database?
Use DATABASE instead of DBNAME, i think this is the problem:
$resource = new PDO('odbc:driver=FreeTDS;Server=127.0.0.1;Port=8090;DATABASE=DATABASENAME;UID=Reporting;PWD=readonly;');
did you try to do the Standard operation? like....
new PDO("odbc:Driver={SQL Server};Server=127.0.0.1;Database=test;",'sa','password');
and which database you are using? ms sql server or some else?
I am rather new to the PDO library, so I apologize for my inexperience. I am writing a class that uses the PDO library to build and execute queries and return the results, no matter what they are.
Within the class, I detect whether there is an open connection to a database, and if it is the same as the one being configured, it uses this one instead. This is really easy to do using the MsSQL library as the PDO::getAttribute() function returns 'CurrentDatabase' and 'SQLServerName', so I can just apply a condition like so:
if(!empty($this->PDO)){
// Get the current connection information
$current_connection = $this->PDO->getAttribute(PDO::ATTR_SERVER_INFO);
// Return if the connection is the same
if($this->connection_parameters['hostname']==$current_connection['SQLServerName']&&$this->connection_parameters['database']==$current_connection['CurrentDatabase']){
return;
}
}
However, when it comes to MySQL, the data returned from PDO::getAttribute is completely different and I cannot seem to get the database name from the current connection.
Does any body know a function or method to get the currently connected database of a MySQL connection using the PDO library in PHP?
I order to connect to both MySQL and MsSQL, you must have 2 connections. However, changing the database on a live connection is very simple.
The following simply checks if a PDO instance already exists and whether or not it is using the required database. If so then it continues with this connection, if not it changes the database.
// Test if the PDO object already exists
if(!empty($this->PDO)){
// If connection is the same then select the database
if($this->connection_engine==$this->PDO->getAttribute(PDO::ATTR_DRIVER_NAME)){
// Get the current database in use
$database = $this->PDO->query("SELECT {$this->select_db_function}");
$database = $database->fetchAll(PDO::FETCH_NUM);
$database = $database[0][0];
// If the current database matches the new database then return
if($database==$this->connection_parameters['database']){
return;
}
}
}
I see no point in looking for the opened connection and - especially - in checking for the current database.
Why can't you just open the connection, select the database for it and then use this connection all the time throughout your class - just like everyone does?
See comments on the MySQL manual page for 'USE database'
I'm using HostMonster as my web host and I'm trying connect to a database I created using MySQL inside of HostMonster. In order to call that database in my website do I need to use PHP? Or is there a way to create a javascript OnClick function that can call the database. I'm not using ASP.Net so it's not quite as simple as I would like it. Just curious if the best solution is PHP, if so I guess I should go learn it.
what are you planning to do with the database, other than just 'calling it'? You will need some language like PHP to connect to the DB to retrieve, insert, update or delete data in the DB.
here is a code for connection MySQL from PHP using MYSQLI extension
<?php
$dba_host='localhost';
$dba_name='root';
$dba_pass='';
$dba_db='sn';
$con=mysqli_connect($dba_host,$dba_name,$dba_pass,$dba_db) or die('Connection Refused !');
$stmt=mysqli_prepare($con,"SELECT UID FROM Main");
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $value);
while(mysqli_stmt_fetch($stmt))
$result[] = $value;
mysqli_stmt_close($stmt);
mysqli_close($con);
?>
Your javascript onClick function is running on the client side (in the browser) and the database is running on the server-side. You will need a server-side language to get the information from the database and send it to the browser.
You do not HAVE to use PHP to connect to a MYSQL database. Also, you can't connect to your database using only client-side javascript (ie. an onClick() function). You need to use a server side language, PHP is one choice.
To connect to a MYSQL database on hostmonster using PHP you will need to know your credentials that use to log into phpMyAdmin from your cpanel. Once you have made the connection you can then select the MYSQL database that you created. Once the database is selected you can query it using the "mysql_query" function in PHP. The following code does all of that and stores the results of the MYSQL query in a PHP variable called $result.
<?php
$con = mysql_connect("www.yourdomain.com","phpMyAdmin_username","phpMyAdmin_password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mysql_database_name", $con);
$query = "SELECT * FROM TableName"
$result = mysql_query($query);
?>
Now you've got the results of the query inside the PHP variable $result and you can use it anyway you like.
If you put this in your 'public_html' folder and named it 'index.php' or 'index.html' this would automatically be run when someone went to www.yourdomain.com.
You can find a great tutorial series on PHP here http://thenewboston.org/list.php?cat=11.
I try to use the code below to show table structure in html page:
<HTML>
<HEAD>
<TITLE>PHP + Firebird / Interbase test (connection)</TITLE>
</HEAD>
<BODY>
<H3>FB Connect test.</H3>
<?php
// DB definition of account
define("DBNAME","xx.xxx.xx.xxx:D:\DATABASE\OCS DATA.FDB"); // data bsse name
define("DBUSER","USER"); // user name
define("DBPASS","USER"); // password
// DB connection
$dbh = ibase_connect(DBNAME,DBUSER,DBPASS);
echo ibase_errmsg();
if ($dbh == FALSE) {
echo 'could not connect to DB<BR>';
} else {
echo 'success to connect to DB<BR>';
}
$ibsql = "SHOW TABLE DOC_TO";
echo ibase_errmsg();
$result=ibase_query($ibsql);
echo $result;
?>
</BODY>
</HTML>
but why it just show the result as "success to connect to DB"?
Firebird does not seem to have a SHOW TABLE or SHOW TABLES command which are specific to MySQL.
The documentation on the IBphoenix web site states that the SHOW TABLES command is only available in the isql command line tool and nowhere else.
In MySQL, you can do SHOW TABLES. You
can use the same in Firebird's isql
command-line tool, but nowhere else.
It goes on and provides the following SQL code as a roughly equivalent solution:
SELECT RDB$RELATION_NAME FROM RDB$RELATIONS;
This query will show you both system
and user tables. To select user tables
only, use this:
`SELECT RDB$RELATION_NAME FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG = 0;
Maybe you can get something equivalent from what you were trying to accomplish by querying the RDB$RELATIONS table (or maybe some other runtime information tables provided by Firebird). See also Lorenzo Alberton's post on extracting META information from a Firebird database.
Note than in PHP you should use single quotes $reqest = 'select ...'; otherwise the $ symbol will be translated as PHP variable sign.