How do I upload my MySQL DB to Heroku for use with a PHP app? The only docs I found on Heroku are this:
Using ClearDB with PHP
Connecting to ClearDB from PHP is super easy, and merely requires the parsing of the CLEARDB_DATABASE_URL to get connected, like this:
<?php
$url=parse_url(getenv("CLEARDB_DATABASE_URL"));
$server = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$db = substr($url["path"],1);
mysql_connect($server, $username, $password);
mysql_select_db($db);
?>
I don't understand how to fill the ClearDB with my data without an SSH connection, or how to create a database or how to connect to it?
From ClearDB's Developer Center FAQ:
For importing data into your MySQL database, we recommend that you use both the mysql command line client as well as the mysqldump database backup utility.
Assuming you have the connection information available, use the mysql and mysqldump utilities on your local machine to connect directly to ClearDB remotely and import the data. This other SO answer may help: How to copy a Database from one server to another server in PHP?
You can export a database dump with mysql_dump locally, and then given the username/password/host information from heroku config, you can use they mysql utility locally to import to the remote host, so something like this:
$ mysqldump --user=db1user --password=db1pass local_database > db.sql
$ mysql --host=remote_host --user=db2user --password=db2pass myschema < db.sql
Related
I'm using WampServer and PHP7. I'm trying to connect to a MS Access database that I created and named "db_operation.accdb". I moved that database to "C:\wamp\www\Operation-Monitor\db". I can't seem to figure out how to connect to it. Although, I can perfectly see it when I browse "127.0.0.1\Operation-Monitor\db". However, I'm clueless about connecting it.
$mysql_user = "";
$mysql_password = "";
$mysql_database = "127.0.0.1\\Operation-Monitor\\db\\db_operation.accdb";
$db = odbc_connect("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$mysql_database;Persist Security Info=False;", $mysql_user, $mysql_password) or die ("Couldn't find any databases.");
I'm getting the following error when I execute my code:
https://i.imgur.com/gERtbhD.png
To get a seamless portable database storage which works with office products as well as server based i suggest to have a look at SQLITE. The database is inside a single file which makes it highly portable between devices. It is open source, supportetd on many OS and has working connectors foe nearly anything possible. In your case you can have for example a fast ado connector in the WAMP server and on Excel and friends a native VBA connector.
I have a client requirement to secure our application connection with the Oracle Database. Currently, we are using OCI8 PHP library (oci_connect) to connect to Oracle using credentials which we have in a config file (a kind of plain text) where we maintain all our credentials.
Now they want to improve the security by implementing some kind secure connection using SSH so communication from application to DB will be secure. I read on the internet that this is possible.
My problem is that I don't know to achieve that with PHP OCI library even if our administrator implement SSH based authentication between the application server and DB server because OCI library uses username and password to connect with DB server.
I am trying to understand if there is any way we can achieve this type of auth connections from PHP to Oracle.
I am using Oracle 12c Enterprise edition.
To answer the second part - Establishing a secure connection using SSH. We can try using Oracle Wallets. So we don't need to save any plain text password in the app server.
Try connecting from PHP to an Oracle DB using an Oracle Wallet using below steps
1 - Create a wallet (https://docs.oracle.com/cd/B19306_01/network.102/b14266/cnctslsh.htm#g1033548)
2 - Put the Oracle instant client and the wallet files somewhere on the server with PHP (for example /opt/instantclient and /opt/wallet)
3 - Start Apache with the following variables:
ORACLE_HOME=/opt/instantclient
LD_LIBRARY_PATH=/opt/instantclient
TNS_ADMIN=/opt/wallet
4 - In /opt/wallet create a tnsnames.ora files with this content:
WALLET_NAME =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = DB_IP)(PORT = DB_PORT))
(CONNECT_DATA = (SID = DB_SID))
)
where WALLET_NAME it's the name of the wallet chosen when the wallet has been created, DB_IP it's the database ip address or hostname, DB_PORT it's the db port, and DB_SID it's the sid of the database
5 - In /opt/wallet create a sqlnet.ora files with this content:
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /opt/wallet)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
6 - Restart Apache
On the PHP code side now you can connect to the database opening a connection with the following code:
$conn = oci_connect("/", "", "WALLET_NAME", null, OCI_CRED_EXT);
OCI_CRED_EXT This tells Oracle to use External or OS authentication, which must be configured in the database. The OCI_CRED_EXT flag can only be used with username of "/" and a empty password.
I'm trying to connect to remotemysql on another server and i've all the authentications and these authentication are working well to connect to remote sql in VISUAL STUDIO and PHP STORM but when i open up the url royalresidency.pk/administration and try to login and it gives me this error i don't understand this error i tried to allow that from from remotesql also and also this ip is allow but still i can't get access to sql from this server what can be the issue ?
$connect = new PDO('mysql:host=65.60.37.227;dbname=cricflip_RoyalResidency',$dbuser, $dbpass);
return $connect;
Try to check your mysql connection. Try connecting with command line. (Mysql should be preinstalled in your system)
mysql -u USERNAME -pPASSWORD -h REMOTE_SERVER_IP DB_NAME
I am install service MySQL to my PHP app on Bluemix and the error is on connection establish on this lines:
$con = mysql_connect("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv");
if (!$con){
echo "Failed to connect to MySQL: " .mysql_error();
}
mysql_select_db("d65a2b7e14b594d18a049ac918a4a8603",$con);
Quentin suggested to use mysqli instead of mysql_* as the latter is deprecated, i.e. try this:
$mysqli = new mysqli("192.155.247.248:3307","uqDqUZ2EKoZ5I","pWXeBZbNtdpOv", "MYDB");
$result = $mysqli->query("SELECT * from MYTABLE");
$row = $result->fetch_assoc();
Create a folder
.bp-config/options.json in the parent folder
and add
{
"PHP_EXTENSIONS": ["mysqli"]
}
in the options.json folder
the sqli connect will work fine now
Are you getting:
ERROR 2003 (HY000): Can't connect to MySQL server on '$host' (60).
A developer may have asked a similar question on developerWorks.
The answer seemed to be as follows:
Downloaded the latest PHPMyAdmin(4.1.9)
Created a BlueMix application using - cf push -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git
${myPhpAdminApp} . Note: the PHP build pack is used is PHP 5.4.26, which enables multi-byte support (it is different from the Heroku one in the BlueMix docs). This was necessary because the Heroku pack bundled PHP 5.3.27 which
doesn't enable "multi-byte" character support by default. Multi-byte
support is required to be enabled by PHPMyAdmin apparently.
Added the existing MySQL service to this app. And picked the host, port, user, and password details from the VCAP_SERVICES
environment variable.
Copied config.sample.inc.php in the PHPMyAdmin to config.inc.php and added or modified the following lines in it based on the MySQL
service VCAP_SERVICES details picked in previous step -
$cfg['Servers'][$i]['host'] = 'host-ip-from-vcap_services';
$cfg['Servers'][$i]['port'] = 'port-from-vcap_services';
$cfg['Servers'][$i]['user'] = 'user-from-vcap_services';
$cfg['Servers'][$i]['password'] = 'password-from-vcap_services';
Pushed the updates using the above cf push ... again.
I have two servers setup on Amazon AWS. One server is running PHP and the other has MySQL. I can connect to the MySQL database through my terminal and MySQL Query Browser.
I am trying to get a connection between the PHP and MySQL servers.
Here is the PHP Code that I am using (works for "localhost" databases)
$dbbase = 'mydb';
$dbuser = 'myuser'; // Your MySQL username
$dbpass = 'mypassword'; // ...and password
$dbhost = 'localhost:3306'; // Internal IP for MYSQL Server
// connect to database
$dblink = mysql_connect($dbhost, $dbuser, $dbpass)
or die ("System Down");
mysql_select_db($dbbase, $dblink)
or die ("Database Down");
It is my understanding that I should be able to route this an internal AWS traffic, but at this point I will take anything that works and build from there.
Here is what I have done:
Added the ip of the PHP server to the Security Group for MySQL(3306) permissions
Tried to use the internal, external, and private IPs/DNSs of the MySQL Server as the $dbhost variable
Created myuser#% (wildcard) on thy MySQL server
Any ideas or tips would be much appreciated.
I had the same issue - turns out MySQL extension for PHP is NO longer included in PHP5!
"In PHP 5 (updated PHP 5.0.4), the following changes exist. Built in: DOM, LibXML, Iconv, SimpleXML, SPL and SQLite. And the following are no longer built in: MySQL and Overload."
Source: http://php.net/manual/en/install.windows.extensions.php
I've got this working.
I think the big trick was to add this rule to the Security Group:
Type: MySQL
Source: 10.0.0.0/8
My understanding is that 10.0.0.0/8 covers all internal amazon IPs. I think you could tighten this up, but it is possible for the internal IP of your servers to change, so that would need to be managed.
Then in my PHP script I used the Private DNS of my MySQL Server. It should look something like this: ip-10-10-100-100.ec2.internal:3306
In the end, I think that is everything that I did.