问题
I'm trying to change steps 4 and 5 so that instead of writing the names/numbers here, the code can go get the information from a SQL database on Bluehost that uses PhpMyAdmin. I don't think this is too difficult but I am a novice. Thank you.
<?php
/* Send an SMS using Twilio. You can run this file 2 different ways:
* - Upload it to a web host and load mywebhost.com/sendnotifications.php
* in a web browser.
* - Local server- Point the web root directory to the folder containing
* this file, and load
* localhost:8888/sendnotifications.php in a web browser.
*/
//Include the PHP TwilioRest Library
// Step 1: Download the Twilio-PHP library from twilio.com/docs/libraries,
// and move it into the folder containing this file.
require "Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$AuthToken = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+14158675309" => "Curious George",
"+14158675310" => "Boots",
"+14158675311" => "Virgil",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased, or the (deprecated) Sandbox number
"YYY-YYY-YYYY",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey $name, Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}
回答1:
Here's a link with a code example of what you'll need.
http://us1.php.net/manual/en/function.mysql-db-query.php
You'll have to setup a simple table like:
CREATE TABLE `people` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
`phone` char(12) NOT NULL
)
Then, you'd access the data with a simple query: SELECT name, phone FROM people;
来源:https://stackoverflow.com/questions/24047394/how-can-i-connect-my-database-to-twilio