如何将我的数据库连接到Twilio

时间:2014-06-04 20:54:49

标签: php database twilio bluehost

我试图更改步骤4和5,以便代码可以从Bluehost上使用PhpMyAdmin的SQL数据库获取信息,而不是在此处编写名称/数字。我不认为这太难了,但我是新手。谢谢。

<?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 个答案:

答案 0 :(得分:1)

这是一个链接,其中包含您需要的代码示例。

http://us1.php.net/manual/en/function.mysql-db-query.php

您必须设置一个简单的表格,如:

CREATE TABLE `people` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(64) NOT NULL,
  `phone` char(12) NOT NULL
)

然后,您可以通过简单的查询访问数据:SELECT name, phone FROM people;