如何将数据库连接到Twilio [英] How can I connect my database to Twilio

查看:96
本文介绍了如何将数据库连接到Twilio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改第4步和第5步,以使代码可以从使用PhpMyAdmin的Bluehost上的SQL数据库中获取信息,而不必在这里写下名称/数字。我认为这不太困难,但我是新手。谢谢。

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";
}


推荐答案

下面是带有代码的链接

http://us1.php.net/manual/zh/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;

这篇关于如何将数据库连接到Twilio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆