I did as following
MySQL 5.1 database added. Please make note of these credentials:
Root User: xxxxxxx
Root Password: xxxxxxx
Database Name: php
Connection URL: mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/
You can manage your new MySQL database by also embedding phpmyadmin-3.4.
The phpmyadmin username and password will be the same as the MySQL credentials above.
phpMyAdmin 3.4 added. Please make note of these MySQL credentials again:
Root User: xxxxxxx
Root Password: xxxxxxx
URL: https://php-doers.rhcloud.com/phpmyadmin/
and i try to connect db using bellow PDO code .but it does not work
$dbh = new PDO('mysql:host=mysql://$OPENSHIFT_MYSQL_DB_HOST:$OPENSHIFT_MYSQL_DB_PORT/;dbname=php', "xxxxxx, "xxxxxx");
I don't know what is the connection URL mean ?
There is an error in your connection string plus $OPENSHIFT_MYSQL_DB_* are env variables and need to be fetched via getenv php function.
So try the following:
define('DB_HOST', getenv('OPENSHIFT_MYSQL_DB_HOST'));
define('DB_PORT',getenv('OPENSHIFT_MYSQL_DB_PORT'));
define('DB_USER',getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
define('DB_PASS',getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));
define('DB_NAME',getenv('OPENSHIFT_GEAR_NAME'));
$dsn = 'mysql:dbname='.DB_NAME.';host='.DB_HOST.';port='.DB_PORT;
$dbh = new PDO($dsn, DB_USER, DB_PASS);
Open php myadmin from webconsole , and on left corner you will get some Ip
That is like xx.xx.xx.xx:3306 , so your hostname is xx.xx.xx.xx
Ip address wil work , I have tried and worked for me
below code worked for me ,try this it might help you
var mysql = require('mysql');
var mysql = require('mysql');
exports.pool = mysql.createPool({
host: process.env.OPENSHIFT_MYSQL_DB_HOST || 'localhost',
port: process.env.OPENSHIFT_MYSQL_DB_PORT || '3306',
user: process.env.OPENSHIFT_MYSQL_DB_USERNAME || 'root',
password: process.env.OPENSHIFT_MYSQL_DB_PASSWORD || '',
database: 'chichat' || 'chichat',
multipleStatements : true,
charset: 'utf8'
});
I would like to add some information to future reference.
Today I am trying to deploy a Drupal installation to Open Shift (OS) and tried to configure MySql.
I connected to OS via SSH (rhc ssh ), went to app-root/data/sites/default. Following cat settings.php to see how OS configure database.
Here it is:
// When run from Drush, only $_ENV is available. Might be a bug
if (array_key_exists('OPENSHIFT_APP_NAME', $_SERVER)) {
$src = $_SERVER;
} else {
$src = $_ENV;
}
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => $src['OPENSHIFT_APP_NAME'],
'username' => $src['OPENSHIFT_MYSQL_DB_USERNAME'],
'password' => $src['OPENSHIFT_MYSQL_DB_PASSWORD'],
'host' => $src['OPENSHIFT_MYSQL_DB_HOST'],
'port' => $src['OPENSHIFT_MYSQL_DB_PORT'],
'driver' => 'mysql',
'prefix' => '',
),
),
);
$conf['file_private_path'] = $src['OPENSHIFT_DATA_DIR'] . 'private/';
$conf['file_temporary_path'] = $src['OPENSHIFT_TMP_DIR'] . 'drupal/';
So I created a php folder into git repository (see OS documentation about Drupal), copied a clean Drupal install to it and paste code above to settings.php.
After pushing to git, restarted OS app and worked!
Related
I successfully tested that my PHP can connect to my MS SQL SERVER.
<?php
$server = 'SRV-MEXAL';
// Connect to MSSQL
$link = mssql_connect($server, 'mexal_db_usr', 'password_changed');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
} else {
echo "Works <br>";
$OK = mssql_select_db ("at6_rp");
echo $OK ? "ok" : "ko";
}
?>
Using this script I got both Works and ok, so connection and db selection are both working.
I tried to configure my db connection into Yii 1 main.php
"mexal_db" => array (
'class' => "CDbConnection",
'connectionString' => 'sqlsrv:Server=SRV-MEXAL; Database=at6_rp',
'enableParamLogging' => false,
'username' => 'mexal_db_usr',
'password' => 'password_changed',
'charset' => 'utf8',
),
But when trying to instantiate it, I got this exception
CDbException' with message 'CDbConnection failed to open the DB connection: could not find driver' in /var/www/httpdocs/test1.phonix.it/yii/framework/db/CDbConnection.php:399
What am I doing wrong?
You will have php.ini inside your project folder. (In yii2, i am having inside web folder. In yii1, I don't know where php.ini file is located.)
So, please find your php.ini file of your project folder.
Inside php.ini, search for pdo_mssql.so.
;extension=pdo.so
;extension=pdo_mssql.so
Remove ; from it. Like
;extension=pdo.so
extension=pdo_mssql.so
Restart your server. It will work.
For more info, check this could not find driver - Yii
I installed mongo 3.0.0 on my ubuntu server.
I tried to use PHP (with appropriate lib installed) to connect to mongo to learn sth new. Unfortunaltey I cannot go any further.
My user configuration looks like this:
> use testdb
switched to db testdb
> show users
{
"_id" : "testdb.testdb",
"user" : "testdb",
"db" : "testdb",
"roles" : [
{
"role" : "readWrite",
"db" : "testdb"
}
]
}
Then I try to execute the following PHP code:
try{
$uri = "mongodb://testdb:password#xxx.xxx.xxx.xxx:27017/testdb";
$options = array("connectTimeoutMS" => 30000);
$client = new MongoClient($uri, $options );
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
die();
}
$db = $client->selectDB("testdb");
I get "Message: Failed to connect to: xxx.xxx.xxx.xxx:27017: Authentication failed on database 'testdb' with username 'testdb': auth failed".
In /etc/mongod.conf I have "auth = true" uncommented
I also verified the conncetion with:
> nc -w 3 -v xxx.xxx.xxx.xxx 27017 Connection to xxx.xxx.xxx.xxx 27017
> port [tcp/*] succeeded!
I dig through Internet, i spent few hours already on this, I even re-installed mongo and set everything up again without any success.
Could you point to where to look for solution?
The authentication schema of 3.0 is not compatible with 2.x drivers. One way you should be able to make it work is by downgrading the authentication mechanism:
use "admin"
var schema = db.system.version.findOne({"_id" : "authSchema"})
schema.currentVersion = 3
db.system.version.save(schema)
Then create a user and you should be able to connect with it.
I created a database called learning-laravel and I created a table which is users I want to get data from that table I wrote this code block:
Route::get('/',function()
{
$users = DB::table('users')->get();
return $users;
});
but I'm getting this type of error:
PDOException
SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:3306' (2)
*/
public function createConnection($dsn, array $config, array $options)
{
$username = array_get($config, 'username');
$password = array_get($config, 'password');
return new PDO($dsn, $username, $password, $options);
}
Try instead of including the port in the host, add a "port" key and the port in a seperate key.
'host' => 'localhost',
'port' => '8889'
Looks like it may be trying to use that entire string as the host name.
As you said in your comment above, you have your MAMP settings pointing MySQL requests to port 3306. Here is the correct setting in that case:
'host' => 'localhost',
'port' => '3306'
Also, the "is it plugged in" suggestion would be to make sure your DB is actually running.
The solution is:
'host' => 'localhost:3306',
So i always get a pdo exception when i try to create my db in the constructor of my Mapper class.
on this line:
$this->db = new PDO($dsn, $db_config['username'], $db_config['password']);
this is my dsn creation:
$db_config = array(
'driver' => 'pgsql',
'username' => $dbUser,
'password' => $dbPassword,
'schema' => 'r0628740',
'dsn' => array(
'host' => 'gegevensbanken.khleuven.be',
'dbname' => '2TX31',
'port' => '51314',
)
);
and finaly my constructor:
public function __construct(){
global $db_config;
$dsn = $db_config['driver'] . ':';
foreach($db_config['dsn'] as $key => $value){
$dsn .= $key . '=' . $value . ';';
}
try{
$this->db = new PDO($dsn, $db_config['username'], $db_config['password']);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(($db_config['driver'] == 'pgsql') && isset($db_config['schema'])){
$this->db->query(sprintf("SET SEARCH_PATH TO %s"), $db_config['schema']);
}
}catch (PDOException $e){
var_dump($e->getLine());
error_log($e->getMessage());
}
}
The PHP contains a dll required by pgsql and pgsql_pdo driver libpq.dll...
Add PHP binary path to system path or copy de DLL into Windows\system32. On linux dependency are installed automatically.
I found article somewhere, works for me. Assuming you have installed PostgreSQL and your WAMP installation is on c:\wamp, you will need to copy:
c:\wamp\bin\php\php5.3.9\libpq.dll to c:\wamp\bin\apache\Apache2.2.11\bin.
Make sure you also have the following files:
C:\wamp\bin\php\php5.3.9\ext\php_pdo_pgsql.dll and
C:\wamp\bin\php\php5.3.9\ext\php_pgsql.dll
Also, make sure you have enabled the above 2 files as extensions, either via the WAMP menu (click on WAMP icon on taskbar: PHP > PHP extensions, find the above 2 and 'check' them).
Please note that php5.3.9 and Apache2.2.11 refer to my specific PHP and Apache versions.
Adjust those to suit your installation.
Copying this libpq.dll from c:\wamp\bin\php\php5.3.9\libpq.dll to c:\wamp\bin\apache\Apache2.2.11\bin. has worked for me
I make an script that fill up all ISPConfig tables by itself and now i only need to raise some script to create the needed vhost and the rest of the symblink needed for apache to work.
My Script is working like a charm since i can view all the data correctly using the ISPConfig frontend.
Digging into the ISPConfig panel i see a RaiseEvent function triggered everytime a record is created but i can't trace where it ends and how it perform the creation of the symblink.
Maybe calling some function or cron it can work.
I'm using Apache 2 + PHP 5.3 + MySQL + ISPConfig 3 on Ubuntu Server 10.4
Ok I respond myself.
Since version 3 ISPConfig came with a simple API that let you performe some operation like Adding FTP Users, Websites and Databases.
I left here an example of how to create a database:
$params_db = array(
'server_id' => '1',
'system_user' => "web10",
'system_group' => 'client0',
'active' => 'y',
'type' => 'mysql',
'database_name' => $NAME,
'database_user' => $NAME,
'database_password' => '123456',
'database_charset' => 'utf8',
'remote_access' => 'n',
);
Next we have to create on the ISPConfig panel a "remote user" that allow to comunicate using the webservice.
$soap_username = 'whatever';
$soap_password = 'h4ck3m3';
$soap_location = 'http://localhost:8080/remote/index.php';
$soap_uri = 'http://localhost:8080/remote/';
$client = new SoapClient(null, array('location' => $soap_location, 'uri' => $soap_uri));
So, what's next?
Next we call the webserver function like this:
try
{
//* Login to the remote server
if( $session_id = $client->login($soap_username,$soap_password))
{
echo 'Logged into remote server sucessfully. The SessionID is '.$session_id. "\n";
$client->sites_database_add($session_id, $client_id, $params_db);
//* Logout
if($client->logout($session_id))
{
echo "DB Created\n";
}
}
}
catch (SoapFault $e)
{
die('SOAP Error: '.$e->getMessage());
}
For more information check out this link of howtogeek website: http://www.howtoforge.com/how-to-create-remote-api-scripts-for-ispconfig-3