How to connect MySQl using php on IBM Bluemix? - php

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.

Related

phppgAdmin has more than 1 Error - also Error Loading servers.php

I am trying to learn PostgreSQL and so installed it and phppgAdmin on my laptop.
I went to localhost/phppgadmin, logged in and I get all these errors on the front page:
I tried going troubleshooting on Google, but unfortunately there are not enough answers to this question.
Also, config.inc.php file looks like this after I altered it according to the Tutorial I followed to connect the Database to PHP:
$conf['servers'][0]['desc'] = 'PostgreSQL';
// Hostname or IP address for server. Use '' for UNIX domain socket.
// use 'localhost' for TCP/IP connection on this computer
$conf['servers'][0]['host'] = 'localhost';
// Database port on server (5432 is the PostgreSQL default)
$conf['servers'][0]['port'] = 5432;
// Database SSL mode
// Possible options: disable, allow, prefer, require
// To require SSL on older servers use option: legacy
// To ignore the SSL mode, use option: unspecified
$conf['servers'][0]['sslmode'] = 'allow';
// Change the default database only if you cannot connect to template1.
// For a PostgreSQL 8.1+ server, you can set this to 'postgres'.
$conf['servers'][0]['defaultdb'] = 'template1';
// Specify the path to the database dump utilities for this server.
// You can set these to '' if no dumper is available.
$conf['servers'][0]['pg_dump_path'] = '/usr/bin/pg_dump';
$conf['servers'][0]['pg_dumpall_path'] = 'C:\\xampp\\pgSql\\11.2\\pg_dumpall.exe';
Thank you in advance
EDIT: Is it possible to just user the original pgadmin?!
This error is because the version of phpPgAdmin you are running does not support php7. You can either downgrade your PHP version or run the code from git master, available at https://github.com/phppgadmin/phppgadmin.

Call to undefined function odbc_connect() message while connecting SAP Hana database

I used odbc_connect() in my PHP page to connect to the HANA database. It works fine when i run it locally.
I upload the same PHP page into the server and i am getting this error:
Fatal error: Call to undefined function odbc_connect()
The code:
$connect = odbc_connect("Team6DataSource", "TEAM6", "Password1", SQL_CUR_USE_ODBC);
Team6DataSource = datasource name.
ip address = 54.217.234.218
Can any one please help me?
Thanks
I just go through in google get this instruction this is really helpful for you.
Download the SQL Server ODBC driver for your PHP client
platform. (Registration required.) If the SQL Server ODBC driver
is not currently available for your platform, check the list of
ODBC-ODBC Bridge Client platforms. The ODBC-ODBC Bridge is an
alternative SQL Server solution from Easysoft, which you can
download from this site.
Install and license the SQL Server ODBC driver on the machine where
PHP is installed. For installation instructions, see the ODBC driver
documentation. Refer to the documentation to see which environment
variables you need to set (LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH,
SHLIB_PATH depending on the driver, platform and linker).
Create an ODBC data source in /etc/odbc.ini that connects to the
SQL Server database you want to access from PHP. For example, this
SQL Server ODBC data source connects to a SQL Server Express instance
that serves the Northwind database:
Use isql to test the new data source. For example:
cd /usr/local/easysoft/unixODBC/bin
./isql -v MSSQL-PHP
[MSSQL-PHP]
Driver = Easysoft ODBC-SQL Server
Server = my_machine\SQLEXPRESS
User = my_domain\my_user
Password = my_password
Please copy and paste this script and execute this
<?
/*
PHP MSSQL Example
Replace data_source_name with the name of your data source.
Replace database_username and database_password
with the SQL Server database username and password.
*/
$data_source='data_source_name';
$user='database_username';
$password='database_password';
// Connect to the data source and get a handle for that connection.
$conn=odbc_connect($data_source,$user,$password);
if (!$conn){
if (phpversion() < '4.0'){
exit("Connection Failed: . $php_errormsg" );
}
else{
exit("Connection Failed:" . odbc_errormsg() );
}
}
// This query generates a result set with one record in it.
$sql="SELECT 1 AS test_col";
# Execute the statement.
$rs=odbc_exec($conn,$sql);
// Fetch and display the result set value.
if (!$rs){
exit("Error in SQL");
}
while (odbc_fetch_row($rs)){
$col1=odbc_result($rs, "test_col");
echo "$col1\n";
}
// Disconnect the database from the database handle.
odbc_close($conn);
?>
Replace data_source_name, database_username and database_password
with your SQL Server ODBC data source, login name and password.
To run the script under Apache, save the file below your Apache web
server’s document root directory. For example,
/var/www/apache2-default/php-mssql-connection.phtml. Then view the
file in a web browser:
http://localhost/php-mssql-connection.phtml
If your web browser is not running on the same machine as the web
server, replace localhost with the web server’s host name or IP
address.
To run the script from the command line, save the file.
For example,
/tmp/php-mssql-connection.php. Then run $ php
/tmp/php-mssql-connection.php.
further more Details Refer this LINK
Download this, copy the .dll to PHP folder and in the php.ini file add:
extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll

DB2 connection failed php

I'm trying to connect to remote DB2 via PHP. But have some problems. I've already installed IBM Application developer client.
phpinfo() output:
IBM DB2, Cloudscape and Apache Derby support enabled
Module release 1.9.4
Module revision $Revision: 327944 $
Binary data mode (ibm_db2.binmode) DB2_BINARY
Then, I've got a php file which is looking like:
$database = 'MyDB';
$user = 'db2inst1';
$password = 'mypassword';
$hostname = '1.1.1.1';
$port = 50000;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;PORT=$port;HOSTNAME=$hostname;".
"PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "connection to $database succeeded";
} else {
echo "connection to $database failed";
echo db2_conn_errormsg();
}
And trying to execute this file, I have "connection to MyDB failed", and NO visible response from db2_conn_errormsg(), which is actually making me baffled
Unfortunately, I haven't got a straight access to the remote server with database. But several months ago, when I was using other client, I succeeded to connect to exactly this database. But that time I didn't need to install IBM ADCL. That is why I can guess that problem is on this side. But even if so, I couldn't fix it.
Sorry if I duplicated some question on stackoverflow, but all answers, which I found, were unfortunately useless to me.
I'm using Apache 2.2 and PHP 5.4.
Hope you can help.
Thanks for any replies!
Are you sure you have connectivity to the server? Correct port, server, firewall rules, username, password, database name?
What is the SQL code you are receiving. Try to get the SQL code from PHP, "connection to xx failed" is your own code so it is useless to help you.
Did you install the application development client? which DB2 version are you using? ADCL is old, it was for DB2 8. Since DB2 9.7, clients have different names, and I think you need IBM Data server client in order to compile the php module. For more information, check this website: http://www-01.ibm.com/support/docview.wss?uid=swg27016878
I think you have to catalog the database server (node) and the database in the local machine with the db2 client. It seems that your PHP code uses ODBC driver, and it has to be configured locally.
Your connection string looks like an ODBC connection where as the db2_connect function in PHP needs :-
DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;
It's on the PHP web page.
I have never been able to get ibm_db2 or pdo_ibm working on a remote. They work if DB2 and Apache are on the same machine (like the iSeries) but not if the host is connecting to a remote DB2.
If you read the Doctrine2 PHP drivers for each you will find they redirect to ODBC if the host is not 'localhost' or '127.0.0.1'.
This code works for me
<?php
if (!$db = odbc_connect ( "AS400", $user, $password) )
echo 'error!';
$result = odbc_exec($db, "select count(*) from $table");
while (odbc_fetch_row($result)) {
var_dump($result);
print_r($result);
echo "\n";
echo odbc_result($result, 1)."\n";
}
odbc_close($db);
AS400 is DSN name defined in ODBC.

MySQL failing to establish a connection using PHP

Using ubuntu 12.04 64 bit on Lenovo t410.
Using apache2 and Mysql 5.5 and attempting to connect via localhost
I am attempting to establish a connection to a database that I made on localhost. When the line of code is reached to establish a connection, it seems Mysql simply hangs, and there is no error message displayed after. I verified that an echo works immediately prior to the connection attempt. I know that apache2 server is working as I can access the index page and display my html form.
I have tried etc/mysql/my.cnf setting the bind address to localhost.
My line of code looks like:
// Attempts to establish connection to MySql server
$connection = mysql_connect("localhost","username","password");
// Prints error message if the connection to MySql fails
if (!$connection){
die("Connection failed: " . mysql_error());
}
echo "Connection established.";
I tried the connection line with single quotes and with no semi-colon as well.
I am willing to post the contents of any configuration file I have if the error isn't syntax. I haven't done anything fancy to Ubuntu, everything is the default install. I am new to CS and especially databases, PHP, and networking. This is my little experiment that I am stuck on.
Any help is greatly appreciated. Thanks,
Don
Can it be, because there is no error message, that the connection IS established, but you didn't do anything with it?
I mean, what is the rest of your code, is there after your code here something like:
mysql_select_db("database_name",$connection);
After reading your last comment, it appears the mysql extensions are not being loaded. Have a look at your php.ini, uncomment the following line (remove the semicolon at the beginning of the line) and restart your apache:
extension=php_mysql.so
Make sure the extension exists in the php extensions directory.
Due to the fact that you are using MySQL version > 4.1.3 it is strongly recommended that you use the mysqli extension instead. Have a look at this: PHP: MySQL Overview
try to set
$mysql_user = "your_username";
$mysql_pass = "your_password";
$mysql_server = "Servername";
$link = mysql_connect($mysql_server,$mysql_user,$mysql_pass);
if (!$link) {
header('HTTP/1.1 500');
exit();

Trouble connecting to SQL Server with PHP

I'm trying to connect to my local SQL Server 2008 R2 (have also tried it with 2005, same result exactly) with PHP. I'm using PHP 5.1 which still supports php_mssql and mssql_connect().
for some reason PHP just won't find my server, I can connect via ODBC flawlessly an that's fine, but I would like to connect to SQL Server directly.
I have connected PHP to SQL Server a million times on different servers, this one seems to be the only one giving me issue.
This is my little test code to try and get the connection working.
//define connection garbage
$db['hostname'] = "USER90C6\SQLEXPRESS";
$db['username'] = "user";
$db['password'] = "password";
$db['database'] = "kal_auth";
//connection string
$conn = mssql_connect($db['hostname'], $db['username'], $db['password']);
//does it work? :o
if($conn)
{
echo "works";
}
else
{
echo "fails";
}
The error this code produces:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: USER90C6\SQLEXPRESS in C:\xampp\htdocs\test.php on line 9
fails
Is there something seriously wrong with my setup? or am I missing something.
Did you enable TCP/IP on the server's configuration tool?
Is the firewall blocking any ports you might be using?
Are your MDAC (microsoft data access components) updated?
turn on mssql.secure_connection in php.ini
I think you don't miss anything.. Your connection string seems to be right (you receive a "Unable to connect" error..).
In my opinion, you problem can be a version incompatibility or a user privileges mistake. First of all: look at DLL driver you are using in PHP and check it's compatibility with you MSSQL version.
Maybe can be a good idea a fresh PHP install, with the latest stable release, if it is possible. Give a look at: http://www.php.net/manual/en/mssql.requirements.php
Good luck.

Categories