0

I'm trying to insert a simple data on MySQL with the following code I put together.. but for some reason it isn't inserting, the page does not give me any errors either.

enter image description here

class urlShortner
{
    error_reporting(E_ALL); ini_set('display_errors',1);

    global $db;

    try { 
        $db = new PDO("mysql:host=data; dbname="data", 'data', 'data');
        $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch( PDOException $e ) { 
        echo $e->getMessage();
    }

    public  function __construct ( $db ){
        $this->db = $db;
    }

    public function insertInto($long_url)
    {
        $short_url = substr(sha1(mt_rand()),17,6);
        $sth = $this->db->prepare("INSERT INTO url_shortner(long_url, short_url) values(':long_url',':short_url')");
        $sth->execute(array(':long_url' => $long_url, ':short_url' => $short_url));
    }

    insertInto('http://www.google.com');
}
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
iBrazilian2
  • 2,204
  • 6
  • 23
  • 45

0 Answers0