【问题标题】:How can I connect my database to Twilio如何将我的数据库连接到 Twilio
【发布时间】:2014-06-04 20:54:49
【问题描述】:

我正在尝试更改第 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";
}

【问题讨论】:

  • 有可能。您需要对数据库连接进行编码并从那里提取联系人信息。假设您正在使用 MySql 数据库,这是一个很好的起点:w3schools.com/php/php_mysql_intro.asp

标签: php database twilio bluehost


【解决方案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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 2022-08-02
    • 2022-01-15
    • 2020-12-22
    相关资源
    最近更新 更多