I'm coding a discord bot and I want to get the text of my bot's status from my database so I created a PHP file
<?php
$servername = "xxx.xxx.xxx.xxx";
$dbusername = "root";
$dbpassword = "xxxxxxx";
$dbname = "bot";
$conn = mysqli_connect($servername, $dbusername, $dbpassword, $dbname);
mysqli_set_charset($conn, "utf8");
$username = "phph";
$query = "SELECT text FROM bot WHERE username = '$username'";
$result = mysqli_query($conn, $query);
while($row = mysqli_fetch_array($result)){
$text = $row['text'];
}
echo $text;
?>
I get the echo of $text when I execute the PHP file with XAMPP
now I want to know that how can I get the value of $text from PHP to JavaScript
help me please ;(
One of the most important programmer skills is the division of complex problems into small parts.
I understood that in your case you have php
application that returns text on execution and you need to get this text in node js.
So if you run:
$ php app.php
you will see:
some text of Discord message
and you want to import this text into a variable in node js.
There are two possibilities:
Then create app.js
with
console.log(process.argv[2])
And type
$ node app.js example
You will see example
so example
can be accessed as process.argv[2]
So it is enough to type
$ node app.js `php app.php`
to have access to some text of Discord message
In this case, read docs of child process
and in the future please divide your problem into smaller pieces like in this case:
"How to get the result of the command in node js"
without the context of discord, php and Xampp.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.