use one mysqli connection for many queries in a page - connection

there are two php files . file1 is executed by browser. second has functions that are called on ajax calls. till now i was using mysql_query . so i created a connection object only once in file2 . i wrote a stored proc now and as i couldnt execute it with mysql_query i went for 'mysqli_stmt_init' . the php function that executes the stored procedure runs in a loop of ajax calls continuously . i created mysqli connection object only once in file2 as i did for mysql connection object. it didnt work . so i create a mysqli connection object each time that particular php func is called . suggest a better way

Not sure if thats what you're asking for, but you can define new mysqli object only once and then use it in all included code, functions (just remember to pass it as argument or use global.
$mysqli_connection = new MySQLi([details]);
while (1){
$query = "SELECT * FROM table";
$result = $mysqli_connection->query($query);
}
Above pseudocode will execute all the queries using the same connection.

Related

How do I execute a SQL script using a bind variable

I'm running Oracle 18.c on a Windows 10 platform.
I have a large DOS script which calls SQL Plus to run the first SQL script, passing a parameter to it.
The parameter is successfully passed to the first SQL script. In that SQL script I'm trying to append some text to the passed parameter so that it can call a second script using the "#" feature.
DOS Script test1.bat
#echo off
SET value1=2020_01_19_17_00_01
sqlplus my_username/my_password#my_TNS as sysdba #C:\Backups\test1.sql %value1%
SQL Script test1.sql
SET SERVEROUTPUT ON
variable param1 varchar2(512);
variable full_file_name varchar2(512);
BEGIN
:param1 := '&&1';
dbms_output.put_line('The value of the passed parameter is: ' || :param1);
:full_file_name := :param1 || '_f104.sql';
dbms_output.put_line('The new filename would be: ' || :full_file_name);
#:full_file_name;
END;
/
I'm having problems getting the value in :full_file_name to execute from the test1.sql script. If a variable were not involved I would simply use the line #2020_01_19_17_00_01_f104.sql
How do I go about getting the script file whose name is stored in :full_file_name to execute?
I found a way to do this. My sql script now looks like:
Define ffn104 = '&&1._f104.sql'
#&ffn104
exit
Note that in the Define statement I had to put a period after the passed variable &&1 to end its definition. Then I appended _f104.sql.
That solved the problem.

databricks: reading from datawarehouse temp directory

I am writing a function like the following
def fromdw():
df=spark.read \
.format("com.databricks.spark.sqldw")\
.option("url", myurl) \
.option("query",sqlquery)\
.option( "forward_spark_azure_storage_credentials","True")\
.option("tempdir", mytempurl)\
.load()
return df
may I know the option tempdir is compulsory? i want to do a read without tempdir , because it was slow as it require to stage the results in a Blob folder first.
Yes. Use JDBC for smaller, faster queries. Use the Databricks spark connector for SQL DW (Synape) for moving large data sets. This connector bypasses both the Spark Driver node and the Synapse head node, and by using Azure Storage as a staging area, allows the unload and load to be performed in parallel by the clusters in either direction.
JDBC is documented here, and looks like this:
connectionProperties = {
"user" : user,
"password" : pw,
"driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
}
pushdown_query = "(select * from whatever) q"
df = spark.read.jdbc(url=jdbcUrl, table=pushdown_query, properties=connectionProperties)
display(df)
(notice how you have to wrap the SELECT to use a query instead of a table name).

PERL DBI in PL/PERL in POSTGRESQL

Can I use DBI in a pl/perl function created in Postgresql to select any foreign database?
Im getting the error: Unable to laod DBI.pm into plperl
(I know that there are oracle foreign data wrappers, but I just need to store the resultset of a select statement fired against Oracle, MSSQL or PG and store it in Postgres.)
Here is my function (just with the connect string at the moment):
CREATE OR REPLACE FUNCTION sel_ora()
RETURNS VOID AS $$
use DBI;
my $db = DBI->connect( "dbi:Oracle:DBKUNDEN", "stadl", "sysadm" )
|| die( $DBI::errstr . "\n" );
$$ LANGUAGE plperl;
Yes, you can use DBI from within plperl.
Note that for security reasons, plperl restricts access to using perl modules. This is intended for multi-user databases where your postgres users are not trusted.
The solution in plperl is to add a line such as this to your postgresql.conf file:
plperl.on_init = 'use DBI;'
Then DBI will be available within your plperl functions. See docs: https://www.postgresql.org/docs/9.5/plperl-under-the-hood.html
Alternatively, if this security consideration does not apply in your situation, then you can use plperlu (u = unrestricted) instead of plperl. Then you can use any perl module directly from your plperlu code.

Drupal Curl, $GET

I am creating a Drupal 7 node from remote. In my server I have a script that uses
now=$(date)
curl --data "date=$now" http://website.com
That is supposed to send the value of $now to the url. In my remote nodecreate.php form I am using
$node->field_date[$node->language][0]['value'] = $_GET['date'];
To set the value of the date field in the node. Problem is that the node is created successfully, but the date is blank.
I have tried other variations such as setting a value to a string in the remote nodecreate.php like this
$date = $_GET['date'];
$node->field_date[$node->language][0]['value'] = $date;
however that did not work either. Anyone got ideas what is wrong here?
You probably should use the following :
$node->field_date[LANGUAGE_NONE][0]['value'] = $date;
I suppose here that you are using translation on node but not translatable fields.

Is it possible to forge post or get request inside casper,run

I have created a webscraping script in casperJs.
What I want is I need to insert the result which i get from the scraping in sql server database.
I am planning to do it by posting the result on server where it inserts in db.
I have tried the below code to test if it can be done inside casper.run
casper.run(function () {
var finalResult = this.evaluate(somefunction, Obj);
this.open('http://www.testserver.com/post.php?q=test').then(function() {
this.echo('GOT it.');
});
It doesnot make the request nor does it echo GOT It.
I am not sure if this is a neat way to do it. I would rather suggest using SpookyJS and SQL server library for NodeJS.
It can be achieved by 2 ways as below:
1) By using the this.open outside .run
2) By running the casper via php script and insert the results in db from there.

Resources