Welcome! Log In Create A New Profile

Advanced

How to use HExecuteSQLQuery() in WEBDEV PHP?

Posted by Marijan Tomasic 
How to use HExecuteSQLQuery() in WEBDEV PHP?
January 09, 2023 02:04PM
Can someone please write a working example of how to use HExecuteSQLQuery() in WEBDEV PHP?
Re: How to use HExecuteSQLQuery() in WEBDEV PHP?
January 09, 2023 03:41PM
Hi,

Is there something you're not telling us that prompted your question, like what DB are you using and have you already tried anything yourself?

You would develop a PHP site in the same way as any other site; i.e. using WLanguage.

[help.windev.com]
[help.windev.com]

Regards,
Darren.
Re: How to use HExecuteSQLQuery() in WEBDEV PHP?
January 09, 2023 03:58PM
Re: How to use HExecuteSQLQuery() in WEBDEV PHP?
January 09, 2023 10:12PM
All examples of the HExecuteSQLQuery() function in the documentation use the "Data Source" variable type, which is not supported in the PHP configuration.

I need a piece of code like this example, that works in PHP/MySQL:

QRY is Data Source
sMyQry is string = "SELECT * FROM ZIPCODES LIMIT 10" // The SQL query must be specified in this way...
 
HExecuteSQLQuery(QRY, hQueryDefault, sMyQry) // how to write this line in PHP configuration?
HReadFirst(QRY) // is it ok?
Info("here I need value of second colon in first row of query")



Edited 4 time(s). Last edit at 01/10/2023 07:51AM by Marijan Tomasic.
Re: How to use HExecuteSQLQuery() in WEBDEV PHP?
January 12, 2023 01:38PM
I switched to the SQLxxx set of functions, which can do what I wanted.
If someone knows the answer to my question, please write... maybe it will be useful to someone.
Re: How to use HExecuteSQLQuery() in WEBDEV PHP?
January 12, 2023 10:45PM
This may help you, however, I do not know if is going to work or it is what you need.
You need to create the variables

// Connect to the database
$connection = hConnectToSQLite("mydatabase.db");

// Define the SQL query
$query = "SELECT * FROM mytable WHERE id = ?";

// Define the parameters for the query
$params = array(1);

// Execute the query
$result = HExecuteSQLQuery($query, $params, $connection);


// Check for errors
if (!$result) {
echo hErrorInfo($connection);
return;
}

// Fetch the result
$data = hReadSQLRecord($result);

// Close the connection
hCloseSQLConnection($connection);


In this example, we first connect to an SQLite database named "mydatabase.db" using the hConnectToSQLite() function. Then we define a query that selects all columns from a table named "mytable" where the "id" column is equal to 1. The parameter of the query is passed as an array of parameters.

Then we use the HExecuteSQLQuery() function to execute the query. If the function returns false, it means an error occurred and we can use the hErrorInfo() function to get more information about the error. If the function returns a valid result, we use the hReadSQLRecord() function to fetch the result, and finally close the connection using hCloseSQLConnection().
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: