Access to ClearDB on Bluemix with PHP and PDO - php

I'm trying to create a Bluemix Application using PHP and ClearDB (using PDO to connect).
When I try to access the server using my localhost (WAMP) I can get the connection successful message. When I simply copy and past the code on Bluemix, I get the following error:
Fatal error: Class 'PDO' not found in /home/vcap/app/htdocs/includes/db.php on line 43
I'm sure that my credentials works because I used the same credentials to connect via MySQL Workbench.
I'm sure that my syntax is correct because I can connect using localhost (WAMP).
I searched and found that I need to activate the PDO as PHP Extensions (I already see this post Activating PHP extensions in Bluemix but no success).
Some configuration files:
.bp-config -> php -> php.ini
extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so
extension=mysqli.so
extension=mysql.so
extension=mbstring.so
extension=php_pdo.dll
extension=php_pdo_mysql.dll
display_errors = On
display_startup_errors = On
error_reporting = On
.bp-config -> options.json
{
"PHP_EXTENSIONS": ["bz2", "zlib", "openssl", "fpm", "tokenizer", "curl", "mcrypt", "mbstring", "PDO", "pdo_mysql", "mysql", "mysqli"]
}
line 43 from /home/vcap/app/htdocs/includes/db.php
$this->conn = new PDO($strcon, $this->user, $this->password)
Server Logs
Someone can help me to fix it?
Thanks!

I could solve it (with the help of #Jeff and # Marc), here is the solution:
The only thing I needed was:
.bp-config>options.json
{
"PHP_EXTENSIONS": ["bz2", "zlib", "openssl", "fpm", "tokenizer", "curl", "mcrypt", "mbstring", "pdo", "pdo_mysql", "mysql", "mysqli"]
}

Related

How to install mysqli (Fatal error: Class 'mysqli' not found) NO mysqli section in phpinfo() [duplicate]

I just deployed my website to a staging environment and am getting the following error:
Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11
At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:
To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?
Code
class DB
{
public static function GetConnection()
{
return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
}
}
(line 11 is the return new mysql(...);)
Update
I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):
Loaded Configuration File C:\WINDOWS\php.ini
But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?
I got the error corrected by enabling/editing the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache
Christian Mark is right but I think it need:
4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"
5rd login out Computer and login in.
Then it work for me.
If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

MySQLi not found error

I just deployed my website to a staging environment and am getting the following error:
Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11
At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:
To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?
Code
class DB
{
public static function GetConnection()
{
return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
}
}
(line 11 is the return new mysql(...);)
Update
I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):
Loaded Configuration File C:\WINDOWS\php.ini
But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?
I got the error corrected by enabling/editing the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache
Christian Mark is right but I think it need:
4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"
5rd login out Computer and login in.
Then it work for me.
If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

mysql is enabled in php.ini but I'm still getting Call to undefined function mysql_connect()

We have a Windows 2008 server, this morning when we came to the office, we saw that mysql is not working
We are getting this error for a simple connect function
Fatal error: Call to undefined function mysql_connect()
but the strange thing is that mysql extensions are enabled in php.ini file.
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
According to phpinfo() , php using the ini file in C:\PHP and the DLL files exist in the ext folder.
I cannot find a way to solve or at least to find out what is causing this.
I would be grateful if someone could give me some advice
Thanks in advance
for debugging purposes try
if ( !function_exists('mysql_connect') ) {
echo '<pre>mysql extension loaded: ', extension_loaded('mysql') ? 'yes':'no', "\r\n";
$cf = get_cfg_var('cfg_file_path');
echo 'ini file: ', $cf, "\r\n";
if ( !$cf || !file_exists($cf) ) {
echo "no config file\r\n";
}
else {
echo "mysql config options:\r\n";
$mc = array_filter( file($cf), function($e) { return false!==stripos($e, 'mysql') && false!==stripos($e, 'extension'); });
echo join("", $mc);
}
die('no function mysql_connect</pre>');
}
the output should be something like
<pre>mysql extension loaded: no
ini file: C:\Develop\php\php.ini
mysql config options:
;extension=php_mysql.dll
;extension=php_mysqli.dll
extension=php_pdo_mysql.dll
no function mysql_connect</pre>
which indicates that the line extension=php_mysql.dll has been commented out (in my php.ini).
In case this script shows that the php_mysql.dll indeed should have been loaded try to increase the log level of both php and your webserver and check the log file. Maybe windows couldn't load the dll because it depends on another dll which isn't present (in the correct version) anymore. E.g. the php_mysql.dll in "my" ext directory depends on MSVCR110.DLL which is present because I have Visual Studio installed, otherwise installing the Visual Studio 2012 redistributables would be required. Tools like Dependency Walker can show you which dlls are required to run an application and/or dll.
Or it could be that the php_mysql.dll implements a different API version than your php core. E.g. if you have PHP 5.4 installed but the php_mysql.dll is for php 5.1 you will see an API magic key error in the log file.
Restart Your WAMP Or XAMPP Server. You can check with Contral Panel of XAMPP Or WAMP

Debugging PHP ADODB.Connection

I am having a trouble to connect to MS SQL2000 with PHP through COM library.
The message I am getting is:
Could not establish a database connection exception 'com_exception'
with message 'Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC SQL Server Driver][DBMSLPCN]SQL Server
does not exist or access denied.....
I have read through many posts and couldn't find any straight forward sample how to setup PHP in order to connect easily. These are the steps I've taken so far:
1) running MSSQL2000 with TCP/IP and Named Pipes enabled, listening on port 1433
2) installed PHP Version 5.4.16 TS
3) I have the following extensions enabled (related to mssql):
extension=php_com_dotnet.dll
extension=php_pdo_sqlsrv_53_ts_vc9.dll
extension=php_sqlsrv_53_ts_vc9.dll
extension=php_pdo_mssql.dll
extension=php_pdo_odbc.dll
4) I have checked for the COM windows permissions
5) I am sure I have provided the correct database/instance, username, password for the connection string.
6) when I instantiate the COM object with:
$connection = new COM("ADODB.Connection");
print_r($connection);
...I get the "com Object" output response, meaning the class seems to work fine.
What have I overlooked ? I have to connect through ADODB since the whole site I am working on is build on it. Is there a way to debug this? Any help is appreciated.
PROBLEM SOLVED!
After a few days of figuring this out and reinstalling virtually everything including Apache, different PHP and MSSQL versions I have come up with the following. I am not claiming this to be the best solution but it works:
Functional environment:
1) Windows Azure Server with MSSQL 2012
2) Apache 2.2 PHP 5.3.28 - installer: php-5.3.28-Win32-VC9-x86.msi downloaded from:
http://windows.php.net/download/
PHP Extensions (I am listing all but you need just the last few):
[PHP_BZ2]
extension=php_bz2.dll
[PHP_CURL]
extension=php_curl.dll
[PHP_ENCHANT]
extension=php_enchant.dll
[PHP_FILEINFO]
extension=php_fileinfo.dll
[PHP_GD2]
extension=php_gd2.dll
[PHP_GETTEXT]
extension=php_gettext.dll
[PHP_GMP]
extension=php_gmp.dll
[PHP_IMAP]
extension=php_imap.dll
[PHP_INTL]
extension=php_intl.dll
[PHP_LDAP]
extension=php_ldap.dll
[PHP_MBSTRING]
extension=php_mbstring.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_OCI8]
extension=php_oci8.dll
[PHP_OCI8_11G]
extension=php_oci8_11g.dll
[PHP_OPENSSL]
extension=php_openssl.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
[PHP_PDO_OCI]
extension=php_pdo_oci.dll
[PHP_PDO_ODBC]
extension=php_pdo_odbc.dll
[PHP_PDO_PGSQL]
extension=php_pdo_pgsql.dll
[PHP_PDO_SQLITE]
extension=php_pdo_sqlite.dll
[PHP_PGSQL]
extension=php_pgsql.dll
[PHP_SHMOP]
extension=php_shmop.dll
[PHP_SNMP]
extension=php_snmp.dll
[PHP_SOAP]
extension=php_soap.dll
[PHP_SOCKETS]
extension=php_sockets.dll
[PHP_SQLITE]
extension=php_sqlite.dll
[PHP_SQLITE3]
extension=php_sqlite3.dll
[PHP_SYBASE_CT]
extension=php_sybase_ct.dll
[PHP_TIDY]
extension=php_tidy.dll
[PHP_XMLRPC]
extension=php_xmlrpc.dll
[PHP_XSL]
extension=php_xsl.dll
[PHP_EXIF]
extension=php_exif.dll
php_sqlsrv_53_ts_vc9.dll
php_pdo_sqlsrv_53_ts_vc9.dll
extension=php_com_dotnet.dll
The php_pdo_sqlsrv_53_ts_vc9.dll extension pack was downloaded from: http://www.microsoft.com/en-us/download/details.aspx?id=20098
The extension=php_com_dotnet.dll downloaded from: http://originaldll.com/file/php_com_dotnet.dll/29343.html (cannot verify how secure this file is but it works)
The MSSQL 2012 needs to be set as follows:
when creating your database, open the management studio and right click the database instance in the left tree. Make sure that under the properties->security tab you select: "SQL Server and Windows Authentication Mode". Without this you will never connect if you are using the standard username / password method.
Then proceed with creating the database schema and under the main security tab create the new user with username/password related to this database. Make sure you set all permission right i.e: owner, datareader, datawriter.
The PHP connection script I used is as follows:
*===============================================*
function openConnection() {
$dbaseServer = "instance name";
$dbaseIp = "127.0.0.1";
$dbasePort = "1433";
$dbaseName = "databsse name";
$dbaseUser = "username";
$dbasePassword = "password";
$connectionString = ""
."Driver={SQL Server};"
."Network=DBMSSOCN;"
."Server=$dbaseServer;"
."Address=$dbaseIp:$dbasePort;"
."Database=$dbaseName;"
."Uid=$dbaseUser;"
."Pwd=$dbasePassword";
try {
$connection = new COM("ADODB.Connection");
$connection->ConnectionTimeout = 60;
$connection->Open($connectionString);
return $connection;
} catch (exception $e) {
echo "Could not connect - $e";
exit;
}
}
// test query
//===========
$sql = "SELECT * FROM [dbname].[dbo].[tablename]";
$connection = openConnection();
// unnecessary but in my case more time is needed.
$connection->CommandTimeout = 240;
$recordset = $connection->Execute($sql);
if (!$recordset) { $connection->Close(); die("Request failed!"); }
if (!$recordset->EOF) {
while (!$recordset->EOF) {
$test[] = $recordset[0]->value;
$recordset->MoveNext();
}
}
print_r($test);
$connection->Close();
--
I think that's it. Please feel free to correct my post and/or improve it :)

PHP 5.4.7,Apache,win7,sqlite. Error info: Call to undefined function sqlite_open()

My environment:
PHP 5.4.7
Apache
win7
DB is sqlite.
I have already uncomment out below script
extension=php_pdo_mysql.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
extension=php_sqlite3.dll
But it still shows the Error info: Call to undefined function sqlite_open().
below is my php test code.
Anyone can help me?
<?php
phpinfo();
$db = sqlite_open('d:/testsqlite');
$rs = sqlite_query($db, 'select * from testtable');
print_r(sqlite_fetch_all($rs));
You only uncommented the extensions and it does not quarantee that it will work
You can:
Check if it's properly loaded, by executing phpinfo() function or php -i on your CLI, if it's not then check the server error logs (apache?) probably you will get more details, why extensions is not loaded.
EDIT1:
You have sqlite3 version you need to call sqlite class method statically like
sqlite3::open()
Here is query example.
And you can always can use PDO extension.
$db = new PDO('sqlite:mysqlitedb.db');
Connecting to PDO

Categories