PHP ODBC connection to H2 database - php

could you please assist me with this.
I'm trying to connect to a H2 Database using PHP OBDC and I get the following error message:
"SQL error: [unixODBC]Unknown authentication type, SQL state 28000 in SQLConnect"
I use the following to connect:
$DSN = "Driver=PostgreSQL;Server=$Srv;Port=5435;Database=$DB;";
$CID = odbc_connect($DSN,$usr,$pwd);
How do i parse the Authentication type in the connection string.
Thanks.

Try including the user and password in the connection string
$DSN = "Driver=PostgreSQL;Server=$Srv;Port=5435;Database=$DB;UID=$usr;PWD=$pwd";

I managed to get this working through the PHP functions for Postgres SQL.
$conn = pg_connect("host=[host] port=[port number] dbname=[database name] user=[username] password=[password]");

Related

PHP OCI: Connection string (convert from JDBC)

I have below obfuscated connection string in SQL developer which works:
jdbc:oracle:thin:#//xyz-scan.example.com:1521/mydb.example.com
How can I use this in php oci_connect?
$db = 'xyz-scan.example.com:1521/mydb.example.com';
$con = oci_connect('scott', 'tiger', $db, 'AL32UTF8');
Lead to error:
ORA-12545: Connect failed because target host or object does not exist
I can ping the server successfully.
I also tried
$db = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST = xyz-scan.example.com)(PORT=1521))
(CONNECT_DATA=(SERVER=DEDICATED)
(SID=mydb.example.com)';
And instead of SID with service_name. Nothing works.
Above gives this error:
ORA-12154: TNS:could not resolve the connect identifier specified
How do I convert this connection string to work with php oci? (is there a unique way? For a different db I have one with #ldap://... how would I convert that?
The solution to first issue with scan address is simple:
$db = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST = xyz-scan.example.com)(PORT=1521))
(CONNECT_DATA=(SERVER=DEDICATED)
(SID=<sid>)';
The second one with ldap is not so simple. As far as I understood oracle has it's own ldap thingy and in it you store the databases TNS entries. This means you query it like you query any ldap system:
<?php
$ds=ldap_connect("oid.mydomain.com", myport); // Connect to oracle ldap
$r=ldap_bind($ds); // Bind to ldap
$sr = ldap_search($ds, "cn=OracleContext,dc=xyz,dc=abc,dc=com", "cn=dbname"); // Run query xyz.abc.com
$info = ldap_get_entries($ds, $sr); // Get entries
ldap_close($ds);
$dbconnectstring = $info[0]["orclnetdescstring"][0]; // Extract db connect string from ldap search result array
$con = oci_connect('scott', 'tiger', $dbconnectstring);
?>
This script will get full TNS connection string which you can then use with oci_connect.

cannot connect php to postgres database using pg_connect

I just try to connect my php code to postgres database but unfortunately it is not work, here is my code :
<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
$host = "host=127.0.0.1";
$port = "port=5432";
$dbname = "dbname=public";
$credentials = "user=postgres password=postgres";
$db = pg_connect( "$host $port $dbname $credentials" ) or die('Could not connect');;
if(!$db){
echo "Error : Unable to open database\n";
} else {
echo "Opened database successfully\n";
}
browser result :
Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: database "public" does not exist in /var/www/test/pgtest.php on line 11
anybody know what is wrong here ?
Are you sure the name of database is 'public'? As fas as I remember 'public' is a name of default schema inside the PostgreSQL database.
Please make sure the database 'public' really exists.
From the command line, become the postgres user, start psql, and issue the \list command to list your databases. Be sure the database you're trying to open is in the list.
Be sure your pg_hba.conf file allows the database to be opened.
Remove everything except $dbname from the pg_connect call and allow the API to use the defaults. Add parameters back as indicated by the error message(s).
sorry but finally I found that my question was wrong, public and testdb are Schemes inside postgres database,

How make database connection using aura sql?

I am using mysql. And i want to connect with database using aura sql.
<?php
$connection_factory = include '/Aura/scripts/instance.php';
$connection = $connection_factory->newInstance(
// adapter name
'mysql',
// DSN elements for PDO; this can also be
// an array of key-value pairs
'host=localhost;dbname=db_aura',
// username for the connection
'root',
// password for the connection
''
);
$result = $connection->fetchAll('SELECT * FROM tbl_test');
?>
The above code shows the error
Parse error: parse error in C:\wamp\www\1\Aura\src\Aura\Sql\Connection\AbstractConnection.php on line 65
Finally I got it...
The code given above in my question is correct. Error occured due the version of my php i used. PHP version above 5.4 only support this. Now am using php 5.4.12 and aura sql is able to connect with mysql and working well.. Thanks.

Trying to connect with sql server database

I'm trying to connect sql server with php, i'm trying to get info from the database..
Now, here is what i got:
try {
$user = '';
$pass = '';
$objDb = new PDO('mysql:host=192.168.10.250;dbname=WEB_POROSIA',
'$user', '$pass');
$objDb->exec('SET CHARACTER SET utf8');
$sql = "SELECT *
FROM 'WEB_POROSIA'
";
$statement = $objDb->query($sql);
$list = $statement->fetchAll(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
echo $e->getMessage();
}
I receive this error:
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
This is my first attempt to connect php with sql server, and i don't know what this output means, i mean i don't know what might cause it!
I'm using xampp.
Thanks
It appears that you are trying to connect using the wrong driver.
For Sql Server you might want to use PDO ODBC driver not the mysql method you are trying to use.
You need to use a different DBO driver.
Check out other ODBC drivers, i.e PDO.
The code you have written tries to connect to a MySQL database rather than a MSSQL one.
You'll want to do something like this:
$db_connection = new PDO("dblib:dbname=$db_name;host=$host", $username, $password);
You can find more information here: http://grover.open2space.com/content/use-php-and-pdo-connect-ms-sql-server

Connect to SQL Server database in php

I'm having issues getting the mssql extension to work in php. Right now I'm using this following function to connect:
function db_open_connection(&$mssql_connection) {
$mssql_username = "XXXXXXXXX";
$mssql_password = "XXXXXXXXX";
$mssql_server = "XXXXXXXX";
$mssql_connection = mssql_connect($mssql_server, $mssql_username, $mssql_password);
if (!$mssql_connection) {
die("Could not connect to the database. The server said ". mssql_get_last_message());
}
}
and this returns
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: XXXXXXXX in XXXXXXXX\mssql.php on line 6
Could not connect to the database. The server said
I am able to connect to the database using the COM object with
$conn = new COM ("ADODB.Connection") or die("Cannot start ADO");
connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB;
$conn->open($connStr);
though that is a much less coder-friendly interface and I'd rather not have to do it that way if I can help it.
I think the problem is in the string I am attempting to use for $mssql_server. I've read and read through the documentation but I can't figure out what it needs to be, possibly due to my extreme unfamiliarity with non-MySQL databases.
Can anyone point me in the right direction?

Categories