lunes, 29 de enero de 2018

priting random values from mysql

<?php
$link = mysqli_connect("localhost", "root", "1124", "mini_dialer");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
$rand=array();

$query = " select * from  leads";

if ($result = mysqli_query($link, $query)) {

    /* fetch associative array */
    while ($row = mysqli_fetch_assoc($result)) {
        $rand[]=$row[lead_id];

   }

    /* free result set */
    mysqli_free_result($result);

 $key=array_rand ($rand);
 echo "Selecting random element  $rand[$key]"; // this will print rand  value

}


else {mysqli_close($link);
?>


 printf("Error: %s\n", mysqli_error($link));

}


/* close connection */

priting ramdom string and array elements

$q=array("a"=>"are you single ?","b"=>"where do you live","c"=>"how old are you ?","d"=>" what it is your name ?");

$a=array_rand ($q);


echo" $q[$a]"

viernes, 26 de enero de 2018

php creating date object and also adding days

<?php
$date = date_create('2006/12/2');
date_modify($date, '+12 year');
echo date_format($date, 'Y-m-d');

?>

result

2018-12-02

array_filter


array_filter — Filters elements of an array using a callback function

array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )
Iterates over each value in the array passing them to the callback function. If the callback function returns true, the current value from array is returned into the result array. Array keys are preserved.


function test_odd($var)
{
if($var==4){
return true;
}
}


$array2 = array(6, 7, 8, 9, 10, 11,4);
print_r(array_filter($array2, "test_odd"));


result
Array ( [6] => 4 )

because the function returned true, if not will return empty array

martes, 23 de enero de 2018

PHP AMAZON Polly

Here is some sample code to download the TTS as an .mp3 file in the browser, the crucial part is $result->get('AudioStream')->getContents() this is what gets the actual .mp3 data.
require_once 'app/aws/aws-autoloader.php';
$awsAccessKeyId = 'XXXXXXX';
$awsSecretKey   = 'XXXXXXX';
$credentials    = new \Aws\Credentials\Credentials($awsAccessKeyId, $awsSecretKey);
$client         = new \Aws\Polly\PollyClient([
    'version'     => '2016-06-10',
    'credentials' => $credentials,
    'region'      => 'us-east-1',
]);
$result         = $client->synthesizeSpeech([
    'OutputFormat' => 'mp3',
    'Text'         => "My input text",
    'TextType'     => 'text',
    'VoiceId'      => 'Joanna',
]);
$resultData     = $result->get('AudioStream')->getContents();

header('Content-Transfer-Encoding: binary');
header('Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3');
header('Content-length: ' . strlen($resultData));
header('Content-Disposition: attachment; filename="pollyTTS.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');

echo $resultData;
A for links, here are a few:

lunes, 22 de enero de 2018

curl json format

curl -v -X POST https://api.catapult.inetwork.com/v1/users/{userId}/messages \
    -u {token}:{secret} \
    -H "Content-type: application/json" \
    -d \
    '{
        "from": "+12525089000",
        "to": "+15035555555",
        "text": "Hello there from Bandwidth!"
    }'
http://dev.bandwidth.com/howto/sendSMSMMS.html

sábado, 20 de enero de 2018

Insert XML Data to MySql Table

<?php
$conn = mysqli_connect("localhost", "root", "test", "phpsamples");

$affectedRow = 0;

$xml = simplexml_load_file("input.xml") or die("Error: Cannot create object");

foreach ($xml->children() as $row) {
    $title = $row->title;
    $link = $row->link;
    $description = $row->description;
    $keywords = $row->keywords;
    
    $sql = "INSERT INTO tbl_tutorials(title,link,description,keywords) VALUES ('" . $title . "','" . $link . "','" . $description . "','" . $keywords . "')";
    
    $result = mysqli_query($conn, $sql);
    
    if (! empty($result)) {
        $affectedRow ++;
    } else {
        $error_message = mysqli_error($conn) . "\n";
    }
}
?>
<h2>Insert XML Data to MySql Table Output</h2>
<?php
if ($affectedRow > 0) {
    $message = $affectedRow . " records inserted";
} else {
    $message = "No records inserted";
}

?>
http://phppot.com/php/insert-xml-data-to-mysql-table/

curl option



Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.
-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).
-c, --cookie-jar <file name> File to save response cookies to.
-d, --data <data> Send specified data in POST request. Details provided below.
-f, --fail Fail silently (don't output HTML error form if returned).
-F, --form <name=content> Submit form data.
-H, --header <header> Headers to supply with request.
-i, --include Include HTTP headers in the output.
-I, --head Fetch headers only.
-k, --insecure Allow insecure connections to succeed.
-L, --location Follow redirects.
-o, --output <file> Write output to . Can use --create-dirs in conjunction with this to create any directories specified in the -o path.
-O, --remote-name Write output to file named like the remote file (only writes to current directory).
-s, --silent Silent (quiet) mode. Use with -S to force it to show errors.
-v, --verbose Provide more information (useful for debugging).
-w, --write-out <format> Make curl display information on stdout after a completed transfer. See man page for more details on available variables. Convenient way to force curl to append a newline to output: -w "\n" (can add to ~/.curlrc).
-X, --request The request method to use.

POST

When sending data via a POST or PUT request, two common formats (specified via the Content-Type header) are:
  • application/json
  • application/x-www-form-urlencoded
Many APIs will accept both formats, so if you're using curl at the command line, it can be a bit easier to use the form urlencoded format instead of json because
  • the json format requires a bunch of extra quoting
  • curl will send form urlencoded by default, so for json the Content-Type header must be explicitly set
This gist provides examples for using both formats, including how to use sample data files in either format with your curlrequests.

curl usage

For sending data with POST and PUT requests, these are common curl options:
  • request type
    • -X POST
    • -X PUT
  • content type header
  • -H "Content-Type: application/x-www-form-urlencoded"
  • -H "Content-Type: application/json"
  • data
    • form urlencoded: -d "param1=value1&param2=value2" or -d @data.txt
    • json: -d '{"key1":"value1", "key2":"value2"}' or -d @data.json

Examples

POST application/x-www-form-urlencoded

application/x-www-form-urlencoded is the default:
curl -d "param1=value1&param2=value2" -X POST http://localhost:3000/data
explicit:
curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/data
with a data file
curl -d "@data.txt" -X POST http://localhost:3000/data

POST application/json

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data
with a data file
curl -d "@data.json" -X POST http://localhost:3000/data
https://gist.github.com/subfuzion/08c5d85437d5d4f00e58

https://curl.haxx.se/docs/httpscripting.html#GET

miércoles, 17 de enero de 2018

php odbc


https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel/

https://zend18.zendesk.com/hc/en-us/articles/218197897-Configuring-a-Linux-Server-to-Connect-to-an-MSSQL-Database-Using-ODBC

http://asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/installing_configuring_odbc.html

http://www.stevepiercy.com/articles/how-to-install-and-configure-freetds-as-an-odbc-connector-to-microsoft-sql-server-on-centosrhel-for-lasso-9/



  541  curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/mssql-tools.repo
  542  sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools
  543  sudo yum install unixODBC-devel
  544  echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
  545  echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
  546  source ~/.bashrc



https://www.ibm.com/developerworks/library/os-php-odbc/index.html

 isql -v asterisk-connector FreePBX mypasss DataElyonN_Test


echo "select GETDATE();" | isql -v asterisk-connector FreePBX mypass


echo " select * from tblAttendanceByPhone;" | isql -v asterisk-connector FreePBX mypass


select script

<?php

// Replace the value's of these variables with your own data:
    $dsn = "asterisk-connector"; // Data Source Name (DSN) from the file /usr/local/zend/etc/odbc.ini
    $user = "FreePBX"; // MSSQL database user
    $password = "11222"; // MSSQL user password

$connect = odbc_connect($dsn, $user, $password);

//Verify connection
if ($connect) {
    echo "Connection established.";


$sql = "SELECT * FROM tblAttendanceByPhone";

        $rs = odbc_exec($connect,$sql);
        echo "<table><tr>";
        echo "<th>AttendanceByPhoneTeacherCID</th></tr>";
        while (odbc_fetch_row($rs))
         {
         $result = odbc_result($rs,"AttendanceByPhoneTeacherCID");
         echo "<tr><td>$result</td></tr>";
        $result1 = odbc_result($rs,"AttendanceByPhoneID");
         echo "<tr><td>$result1</td></tr>";
        }
        odbc_close($conn);
        echo "</table>";
odbc_close($connect);
} else {
    die("Connection could not be established.");
}
?>

Update

<?php

// Replace the value's of these variables with your own data:
    $dsn = "asterisk-connector"; // Data Source Name (DSN) from the file /usr/local/zend/etc/odbc.ini
    $user = "FreePBX"; // MSSQL database user
    $password = "1222"; // MSSQL user password

$connect = odbc_connect($dsn, $user, $password);

//Verify connection
if ($connect) {
    echo "Connection established.";


$sql = "update tblAttendanceByPhone set AttendanceByPhoneTeacherCID='$argv[1]'  where  AttendanceByPhoneID='$argv[2]'";

        $rs = odbc_exec($connect,$sql);

odbc_close($connect);
} else {
    die("Connection could not be established.");
}
if (odbc_error()) {
    echo "I've found a problem: " . odbc_errormsg($conn);
}
?>

nano /etc/odbc.ini


[asterisk-connector]
Description     = MS SQL connection to 'asterisk' database
Driver          = FreeTDS
Database        = DataElyonN_Test
Server          = 192.168.1.97
UserName        = FreePBX
Password        = 1111
Trace           = No
TDS_Version     = 0.95
Port            = 1433
------------------------------------------
nano /etc/odbcinst.ini

[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2
UsageCount=1

[FreeTDS]
Description = Freetds v 0.95
Driver = /lib64/libtdsodbc.so.0

lunes, 15 de enero de 2018

php mssql

https://github.com/Microsoft/msphpsql
https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel/

sábado, 13 de enero de 2018

php xml

<?php
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
    <Say>Hello Monkey</Say>
</Response>

sábado, 6 de enero de 2018

open a url using a select

<!-- Paste this code into the BODY section of your HTML document  -->
<select size="1" name="jumpit" onchange="document.location.href=this.value"> 
<option selected value="">Make a Selection</option>
<option value="http://www.javascriptsource.com/">The JavaScript Source</option>
<option value="http://www.javascript.com">JavaScript.com</option>
<option value="http://www.webdeveloper.com/forum/forumdisplay.php?f=3">JavaScript Forums</option>
<option value="http://www.scriptsearch.com/">Script Search</option>
<option value="http://www.webreference.com/programming/javascript/diaries/">The JavaScript Diaries</option>
</select>
https://stackoverflow.com/questions/5150363/onchange-open-url-via-select-jquery