Skip to content

Instantly share code, notes, and snippets.

@Retter241
Last active April 14, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Retter241/c6693d5c3d32b080010c11c0483cb898 to your computer and use it in GitHub Desktop.
Save Retter241/c6693d5c3d32b080010c11c0483cb898 to your computer and use it in GitHub Desktop.
functions
<?php
/**
* Curl init function
* @param (string)$url
* @param (array)$params
* @return $response
*/
function curlInit($url = '', $params = array())
{
$c = curl_init($url);//.json
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_HEADER, false);
// curl_setopt($c, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
//$response = json_decode($response, true);//if response json
$response = curl_exec($c);
// $response['errors'][] = curl_error($c);
return $response;
}
<?php
/**
* Pretty dump any data
*
* @param $variable
* @param $string
*
* @return $string
*/
function dump($variable, $string = 'DEBUG::')
{
echo date("Y-m-d H:i:s") . ' : <br/>';
echo $string . ' : <br/><pre>';
var_dump($variable);
echo '</pre>';
exit();
}
<?php
/**
* PDO Mysql conn
*
* @param $close
*
* @return (object)$connection
*/
function db($close = false)
{
$host = "localhost";
$db_name = " ";
$login = " ";
$password = " ";
$connection = new PDO('mysql:host=' . $host . ';dbname=' . $db_name, $login, $password, array(
// PDO::ATTR_PERSISTENT => true
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));
if ($close) {
$connection = null;
}
return $connection;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment