Skip to content

Instantly share code, notes, and snippets.

@elmelegy
Last active August 29, 2015 14:25
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 elmelegy/df517553e253eb6fbde5 to your computer and use it in GitHub Desktop.
Save elmelegy/df517553e253eb6fbde5 to your computer and use it in GitHub Desktop.
<?php
class con
{
public $con;
public function __construct(){
$con = mysqli_connect('localhost', 'root', '', 'whatsapp');
if($con){echo 'Connection <br/>';}else{echo 'Problem Connection <br/>';}
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}}
public function conQuery($conQuery){
return mysqli_query($this->con,$conQuery);
}
}
$c = new con();
$r = "INSERT INTO `send`(`id`, `packets`, `phone`, `typ`, `send`, `dat`) VALUES (null,'111111111','22222222','text',0,'1/1/1')";
$e = mysqli_query($c->con,$r);
if ($e) {
echo 'ok';
} else {
echo 'no';
}
Copy link

ghost commented Jul 19, 2015

change the construct like this :

class con {

public function _construct() {
            $con = mysqli_connect('localhost', 'root', '', 'whatsapp');

        if($con){echo 'Connection <br/>';}else{echo 'Problem Connection <br/>';}

        if (mysqli_connect_errno())
        {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        $this->con = $con;
}
}

when use the class do:

$c = new con();
$q = "select * from test";
$e = $c->conQuery($q);
... # your other code here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment