Skip to main content
Topic: database connection for query sql (Read 2838 times) previous topic - next topic

database connection for query sql


Hello everyone, I am very new to phprad and there is a question that I cannot clear.
How can I launch custom sql queries without first connecting to the database. For example:

If I launch a sql query like I would be:

$sql = mysqli_query ($mysqli, "SELECT * FROM table");

but in doing so, it tells me that I have no connection to the database. first you would have to create a connection with:

$mysqli = new mysqli ("localhost", "root", "", "database_bd");

to make it work. This is a problem, because when deploying the project on another server with a different ip / DB, it would be necessary to change the connections in all the files where there were custom queries.

How would you do it in phprad so that when launching the custom query it would use the existing connection to the database?

Greetings and thank you.


Re: database connection for query sql

Reply #2
Hello, thanks for answering. Well the question is a little generic because I will need to do many sporadic queries to complete features that phprad does not have by default. For example a serious one, adding a button to sort the records to each record I will assign a manual code to it, I want that if I delete a code by clicking on that button, I will reorder all the records, for example if I have 1 2 3 and delete the 2 then 3 becomes 2 and so on. I have the query to do it and it works fine in fact, but as I commented in my problem I have to create the connection to the database before writing the query in the page php file.

Another thing I need to do is when I delete a record that is deleted from that table but before it is copied to another table that I will call casualties rather than a deletion would be to move a record from one table to another.

Surely throughout my development I will need to do more things that phprad does not include by default, so I want to know how I can execute sql queries without previously creating the connection to the database, if not use the one that already has the default.

Greetings and thank you.

Re: database connection for query sql

Reply #3
Here is a video on how to use phprad query functions https://www.youtube.com/watch?v=OZnyvphKpZI and this https://www.youtube.com/watch?v=UsLlG4EvkbQ, if you are writing your query on the Page events all you have to do is
Code: [Select]
$db->rawQuery(" Your query then goes here.");
and also search for the keyword rawQuery on the forum to see more discussion on various usage, thanks.

 

Re: database connection for query sql

Reply #4
Thank you very much for your help. It works like this perfectly.