How make database connection using aura sql? - php

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.

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.

Getting Data from Vertica with PHP with wrong Encoding

I'm trying to get data from Vertica DB using php odbc_connect, I have a problem with Russsian text, so for example instead of getting this text Уютная I got an \x1A\x1A\x1A\x1A\x1A\x1A
This is my DNS connection string:
$dsn = "Driver=Vertica;Server={$host};Port={$port};Database={$database};";
$this->connection = odbc_connect($dsn, $username, $password);
And this my /etc/vertica.ini file (app runs in debian Jessie):
[Driver]
DriverManagerEncoding=UTF-16
ODBCInstLib = /usr/lib/x86_64-linux-gnu/libodbcinst.so.1
ErrorMessagesPath=/opt/vertica
LogLevel=4
LogPath=/tmp
I'm using Vertica ODBC driver 7.2.2-0
Any idea how I can fix it?
Thank you !
Temporary solution I found is to wrap the field with URI_PERCENT_ENCODE function (vertica sql function) and in php you do a urldecode.
stackoverflow

How to fix fatal error in PHP?

I found a system that can generate a report I would like to study this system but when I try to generate the system the login was OK but when I put the password and username this error comes out:
Fatal error: Call to undefined function mysql_select_db() in
C:\xampp\htdocs\inventory\inventory\db.php on line 8
Can anyone else tell me what is the problem in this system?
image
I'm currently using XAMPP V3.2.2
If you are using PHP 7 within your XAMPP then it wont work because that code is too old. mysql_select_db was removed in PHP 7.
http://php.net/manual/en/function.mysql-select-db.php
You will need to install PHP 5 to use that software.
Edit: Pratik Solanki is correct also. The database is being connected using mysqli so depending on the other code in the system you can either change the database connect statement to mysql_connect and use PHP 5 (old mysql connector not recommended) or change all the database statements to use mysqli instead in which case no PHP changes are needed (recommended)
You forgot to include the database while connecting using mysqli_connect function.
In your code, you declared a $mysql_database but you didn't use that.
Code:
<php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "liveedit";
$bd = mysqli_connect ($mysql_hostname, $mysql_user, $mysql_password, $mysql_database) or die ("Opps something went wrong ");
?>
You connected to database via mysqli module of php and you are trying to select your database via mysql module of php.
Correct way to use it would be like this :
mysqli_connect(dbhostname,dbusername,dbpassword,dbname)
mysqli can be used with the mysql native drivers and mysql can be used via the default libraries provided.
Both are different and the only small mistake you made was making connection with mysqli and selecting db with mysql.
Solution to this is making the whole connection along with selection of db via mysqli function

Having trouble getting the last id in MySQL

I'm trying to get the last id added to the database using mysql_insert_id but it doesn't work. The error I get is:
mysql_insert_id() [function.mysql-insert-id]: Can't connect to local MySQL server through socket '/var/tmp/mysql.sock' (2) in /proj/co639/assessment2/nicp3/public_html/book_create.php on line 46
Warning: mysql_insert_id() [function.mysql-insert-id]: A link to the server could not be established in /proj/co639/assessment2/nicp3/public_html/book_create.php on line 46
I've done my connection like this:
$handle = new PDO( 'mysql:host=;dbname=', '', '');
What could be the issue?
You are actually looking for this:
$handle->beginTransaction();
// here you execute your query
$handle->commit();
$id = $handle->lasInsertId();
Your code won't work because you mix two different classes.
More information can be found here: http://php.net/manual/en/pdo.lastinsertid.php

PHP ODBC connection to H2 database

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]");

Categories